PHP is_executable() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Filesystem

Definition

In PHP, is_executable() tells you whether a file exists and can be run as a program. It returns true or false.

On Linux and macOS it checks the execute permission of the file. On Windows it checks the file extension, so files ending in .exe, .bat or .cmd count as executable.

Syntax

Call is_executable() with the values you need. Start with this line.

PHP
$canRun = is_executable('/usr/bin/php');
CallWhat it does
is_executable('/usr/bin/php')Returns true if that program exists and can be run.
is_executable(PHP_BINARY)Checks the PHP program that is running your script.
is_executable('notes.txt')Returns false because a text file has no execute permission.

A folder is usually reported as executable on Linux because the execute permission on a folder means you may enter it. Use is_dir() if you need to tell files and folders apart.

Library declarations
PHP
is_executable(string $filename): bool

Parameters

ParameterDescription
filenameRequired. The path to the file to check.

Return Value

Return ValueDescription
boolReturns true if the file exists and is executable, otherwise false.

PHP Examples

Example 1 — Check the PHP Program

PHP_BINARY holds the path of the PHP program that runs your script, so it is a safe file to test.

PHP
<?php
if (is_executable(PHP_BINARY)) {
    echo "PHP binary is executable", PHP_EOL;
} else {
    echo "PHP binary is not executable", PHP_EOL;
}

How It Works

  1. PHP_BINARY is a built-in constant with the full path of the PHP program.
  2. is_executable() checks that the file exists and can be run.
  3. The result is true, so the first message is printed.
  4. Some setups such as php-fpm may leave PHP_BINARY empty, and then the check returns false.

Example 2 — Change Permissions with chmod

On Linux or macOS the execute permission decides the result. This example shows the answer before and after chmod().

PHP
<?php
$file = sys_get_temp_dir() . '/tool.sh';
file_put_contents($file, '#!/bin/sh' . PHP_EOL . 'echo hi' . PHP_EOL);

chmod($file, 0644);
clearstatcache();
echo "Before chmod: ", is_executable($file) ? 'yes' : 'no', PHP_EOL;

chmod($file, 0755);
clearstatcache();
echo "After chmod: ", is_executable($file) ? 'yes' : 'no', PHP_EOL;

unlink($file);

How It Works

  1. The script file is created with the permission 0644, which allows reading and writing but not running.
  2. is_executable() returns false at first.
  3. chmod($file, 0755) adds the execute permission, and clearstatcache() makes PHP forget the old answer.
  4. The second check returns true.

Example 3 — Check Several Paths in a Loop

Loop over a few labelled paths and print whether each one can be run.

PHP
<?php
$paths = [
    'PHP binary'   => PHP_BINARY,
    'This script'  => __FILE__,
    'Missing tool' => __DIR__ . '/no-such-tool',
];

foreach ($paths as $label => $path) {
    echo $label, ': ', is_executable($path) ? 'yes' : 'no', PHP_EOL;
}

How It Works

  1. The array uses a readable label as the key and the path as the value.
  2. The PHP program is executable, so it prints yes.
  3. A normal PHP script file has no execute permission, so it prints no.
  4. A file that does not exist always returns false.

Frequently Asked Questions

It checks whether a file exists and can be run as a program, and returns true or false.
Windows has no execute permission bit, so PHP looks at the file extension. Files such as .exe, .bat and .cmd are treated as executable.
Use chmod($file, 0755) on Linux or macOS. Then call clearstatcache() so PHP does not return an old cached answer.
On Linux the execute permission on a folder means you can enter it. Add an is_file() check if you only want real files.
The check only says that the file can be run. Always validate any user input before you build a command with exec() or shell_exec().

Next: is_file()

is_file() tells you whether a path points to a regular file. It returns true for a file an.

is_file() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful