|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54514 Get php binary path during script execution
Submitted: 2011-04-12 14:11 UTC Modified: 2012-01-27 19:58 UTC
Avg. Score:4.5 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: frederic dot hardy at mageekbox dot net Assigned: laruence (profile)
Status: Closed Package: PHP options/info functions
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2011-04-12 14:11 UTC] frederic dot hardy at mageekbox dot net
Currently, PHP does not provide any solution to retrieve PHP binary path in userland.
There is a workaround with some *NIX shells like bash, which provide $_, available in $_SERVER['_'] in userland.
However, it's not a reliable solution (cron task, etc.), and this hack is not available on Windows.
So, a constant like PHP_BINARY (similar to PHP_VERSION and other PHP_* constants) seems to be a good solution.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-07 08:57 UTC]
PHP does provide a path to the binary directory:

However it is true it doesn't contain the executable itself.
 [2011-12-07 10:32 UTC]
Automatic comment from SVN on behalf of laruence
Log: Implemented FR #54514 (Get php binary path during script execution).
 [2011-12-07 10:37 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2011-12-07 10:37 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

implement in 5.4,  thanks
 [2012-08-23 20:57 UTC] glen at delfi dot ee
could the test be improved not to depend that values match exactly? just the 
existence? because when the test is run from build time (from sourcetree instead 
of installed tree) the binary name is .libs/something due libtool:

001+ string(62) "/home/users/glen/rpm/BUILD/x86_64-linux/php-5.4.6/sapi/cli/php"
001- done
002+ string(71) "/home/users/glen/rpm/BUILD/x86_64-linux/php-
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 11:01:27 2023 UTC