note 49299 deleted from ref.exec by cmb
| From: | cmb@php.net | Date: | Sun, 24 Feb 2019 09:30:04 +0000 |
| Subject: | note 49299 deleted from ref.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210282@lists.php.net to get a copy of this message | ||
Note Submitter: louis dot j dot scoras at gmail dot com
----
To start a process to run in the background, you can use the same technique you would in writing a
daemon. Fork a new child while exiting in the parent, then set that as the process leader.
Finally, fork once more, and run whatever the command is:
<?php
if(pcntl_fork()) {
exit;
}
posix_setsid();
if(pcntl_fork()) {
exit;
}
pcntl_exec('/usr/bin/ogg123', array('-q', $this->findPath()));
?>
Of course, this would be the last thing that your script does, because the parent exits when you
spawn the new process. You could do more fancy things, but this works as a good starting point.