Skip to content

Instantly share code, notes, and snippets.

@aaroncampbell
Created August 21, 2013 13:34
Show Gist options
  • Save aaroncampbell/6294506 to your computer and use it in GitHub Desktop.
Save aaroncampbell/6294506 to your computer and use it in GitHub Desktop.
Find the PHP binary in the path
<?php
/**
* Checks the path for the php binary and returns it's location if found
*
* @return false|string False on failure, String of binary location on success
*/
function get_php_bin_from_path() {
$paths = explode( PATH_SEPARATOR, getenv( 'PATH' ) );
foreach ( $paths as $path ) {
// Windows XAMPP sometimes has the actual bin as the path
if ( strstr( $path, 'php.exe' ) && isset( $_SERVER['WINDIR'] ) && file_exists( $path ) && is_file( $path ) ) {
return $path;
} else {
$php_executable = $path . DIRECTORY_SEPARATOR . 'php' . ( isset( $_SERVER['WINDIR'] ) ? '.exe' : '');
if ( file_exists( $php_executable ) && is_file( $php_executable ) )
return $php_executable;
}
}
return false; // not found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment