Upgrade to Pro — share decks privately, control downloads, hide ads and more …

So that the daemon won’t die

So that the daemon won’t die

Long running processes and PHP

Leszek Krupiński

April 03, 2017
Tweet

More Decks by Leszek Krupiński

Other Decks in Programming

Transcript

  1. So that the daemon won’t die Long running processes and

    PHP Leszek Krupiński 4developers 2017
  2. • redirect streams / close descriptors • fork • detach

    from console • respond to signals • close nicely
  3. 1. Call umask(0) to prevent permission issues. 2. fork() and

    have the parent exit. 3. Call setsid(). 4. Setup signal processing of SIGHUP and SIGTERM. 5. fork() again and have the parent exit. 6. Change the current working dir with chdir(). 7. fclose() stdin, stdout and stderr and don't write to them. 8. Process!