| | |
How to pass information to child processes
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
•
•
Take a look at:
http://pleac.sourceforge.net/pleac_p...gementetc.html
http://www.php.net/proc_open
http://www.php.net/socket_create_pair
http://www.php.net/sem
You're welcome.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Thanks to digital-ether, I found this piece of code:
Thanks again, digital-ether.
By the way, how do I mark this thread as solved?
Hoppy
PHP Syntax (Toggle Plain Text)
// PHP supports fork/exec/wait but not pipe. However, it does // support socketpair, which can do everything pipes can as well // as bidirectional communication. The original recipes have been // modified here to use socketpair only. // ----------------------------- // pipe1 - use socketpair and fork so parent can send to child $sockets = array(); if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets)) { die(socket_strerror(socket_last_error())); } list($reader, $writer) = $sockets; $pid = pcntl_fork(); if ($pid == -1) { die('cannot fork'); } elseif ($pid) { socket_close($reader); $line = sprintf("Parent Pid %d is sending this\n", getmypid()); if (!socket_write($writer, $line, strlen($line))) { socket_close($writer); die(socket_strerror(socket_last_error())); } socket_close($writer); pcntl_waitpid($pid, $status); } else { socket_close($writer); $line = socket_read($reader, 1024, PHP_NORMAL_READ); printf("Child Pid %d just read this: `%s'\n", getmypid(), rtrim($line)); socket_close($reader); // this will happen anyway exit(0); } This is so simple, a child could do it. To communicate in both directions, you can simply not close the pipe that sends data from the child to the parent until the child is finished (after the pcntl_waitpid).
Thanks again, digital-ether.
By the way, how do I mark this thread as solved?Hoppy
Last edited by hopalongcassidy; Nov 20th, 2008 at 3:27 pm. Reason: Solved
•
•
•
•
Thanks to digital-ether, I found this piece of code:
PHP Syntax (Toggle Plain Text)
// PHP supports fork/exec/wait but not pipe. However, it does // support socketpair, which can do everything pipes can as well // as bidirectional communication. The original recipes have been // modified here to use socketpair only. // ----------------------------- // pipe1 - use socketpair and fork so parent can send to child $sockets = array(); if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets)) { die(socket_strerror(socket_last_error())); } list($reader, $writer) = $sockets; $pid = pcntl_fork(); if ($pid == -1) { die('cannot fork'); } elseif ($pid) { socket_close($reader); $line = sprintf("Parent Pid %d is sending this\n", getmypid()); if (!socket_write($writer, $line, strlen($line))) { socket_close($writer); die(socket_strerror(socket_last_error())); } socket_close($writer); pcntl_waitpid($pid, $status); } else { socket_close($writer); $line = socket_read($reader, 1024, PHP_NORMAL_READ); printf("Child Pid %d just read this: `%s'\n", getmypid(), rtrim($line)); socket_close($reader); // this will happen anyway exit(0); } This is so simple, a child could do it. To communicate in both directions, you can simply not close the pipe that sends data from the child to the parent until the child is finished (after the pcntl_waitpid).
Thanks again, digital-ether.By the way, how do I mark this thread as solved?
Hoppy
Right at the bottom of the thread, beside the "reply" button you should see the link to mark the thread as solved.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Nov 2008
Posts: 11
Reputation:
Solved Threads: 1
hi hopalongcassidy,
i think this is usefull to you some how i think http://www.phpeasystep.com/phptu/29.html
i think this is usefull to you some how i think http://www.phpeasystep.com/phptu/29.html
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Other Threads in the PHP Forum
- Previous Thread: Connection problem
- Next Thread: checkbox array storage and retrieval
Views: 1788 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database dataentry date directory display download dynamic echo email error file files folder form forms freelancing function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap sorting source space speed sql structure syntax system table tutorial tutorials update updates upload url validation validator variable video web xml youtube zend






