PHP/lib/proc

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP‎ | lib
Jump to navigation Jump to search
PHP local process management

About

This is probably the most basic of the local process-management libraries[1]; I'm not sure if that's a fair description because I haven't tried any of the other possibly-overlapping libraries yet (see Process Control Extensions).

Model

  • A process is opened by executing a command via proc_open()php.
  • While it is open:
    • it may send output through stdout (information) or stderr (error messages)
    • it may receive input via stdin
    • Its status may be obtained via proc_get_status()php.
    • Its priority is modifiable via proc_nice()php.
    • It may be terminated via proc_close()php (which waits politely for the process to be done) or proc_​terminate()php (which forces the issue).

Unlike SSH2, this library does not have a concept of opening a process without first executing a command; the command is the process. Each command opened with proc_open() is like a separate terminal session. In order to maintain any kind of persistent session-state across multiple commands, you have to first run some kind of wrapper-command like "bash" or "script" and then transmit additional commands to that wrapper-command via stdin. (The meaning of those additional commands will, of course, depend entirely on how the wrapper-command interprets them.)

Links

Footnote

  1. I'm not counting popen() because that doesn't allow dialogue with the process; it just runs it and hands you a pipe-stream for either the process's output or your input to it.