PageRenderTime 104ms CodeModel.GetById 94ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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