How can I invoke an external shell script (Or alternatively an external PHP script) from PHP itself and get its process ID within the same script?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
If you want to do this strictly using tools PHP gives you, rather than Unix-specific wizardry, you can do so with
proc_open
andproc_get_status
, although the need to pass a descriptor spec intoproc_open
makes it unpleasantly verbose to use:For a cross-platform solution, check out symfony/process.
After you install
symfony/process
with composer (composer require symfony/process
), you may need to update autoloading info withcomposer dump-autoload
and then require the autoload withrequire __DIR__ . '/vendor/autoload.php';
.Notice also that you can get PID of a running process only. Refer to the documentation for API details.