Created
August 21, 2013 13:34
-
-
Save aaroncampbell/6294506 to your computer and use it in GitHub Desktop.
Find the PHP binary in the path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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