/framework/experimental/pherver/proc_open_parent.php

http://zoop.googlecode.com/ · PHP · 47 lines · 29 code · 12 blank · 6 comment · 0 complexity · 4f6cfe64cd0686ba6590e6ee2756dd30 MD5 · raw file

  1. #!/usr/bin/env php
  2. <?php
  3. define('zoop_dir', dirname(__file__) . '/../../framework');
  4. define('app_dir', dirname(__file__));
  5. include(zoop_dir . '/Zoop.php');
  6. Zoop::loadLib('app');
  7. echo "I am the parent\n";
  8. // trigger_error('stuff');
  9. $descriptorspec = array(
  10. 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
  11. 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
  12. 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
  13. );
  14. $process = proc_open('./child.php', $descriptorspec, $pipes, getcwd(), array());
  15. assert(is_resource($process));
  16. while(true)
  17. {
  18. static $i = 1;
  19. echo "writing to the stream $i\n";
  20. fwrite($pipes[0], "Message : parent $i\n");
  21. //fflush($pipes[0]);
  22. echo "getting the stream $i\n";
  23. $response = fgets($pipes[1], 4096);
  24. echo "printing the stream $i\n";
  25. echo "$response";
  26. // echo stream_get_contents($pipes[1]);
  27. echo "printed the stream $i\n\n";
  28. $i++;
  29. }
  30. fclose($pipes[0]);
  31. fclose($pipes[1]);
  32. // It is important that you close any pipes before calling
  33. // proc_close in order to avoid a deadlock
  34. $return_value = proc_close($process);
  35. echo "command returned $return_value\n";