note 57932 added to function.pcntl-wait
| From: | thisisroot at gmail dot com | Date: | Wed, 19 Oct 2005 14:14:59 +0000 |
| Subject: | note 57932 added to function.pcntl-wait | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97230@lists.php.net to get a copy of this message | ||
Below is a simple example of forking some children and timing the total duration (useful for stress
tests).
<?php
$isParent = true;
$children = array();
$start = microtime( true);
/* Fork you!
* (Sorry, I had to)
*/
$ceiling = $CONCURRENCY - 1;
for ( $i = 0; (( $i < $ceiling) && ( $isParent)); $i++) {
$pid = pcntl_fork();
if ( $pid === 0) {
$isParent = false;
} elseif ( $pid != -1) {
$children[] = $pid;
}
}
/* Process body */
echo "Do stuff here\n";
/* Cleanup */
if ( $isParent) {
$status = null;
while ( count( $children)) {
pcntl_wait( $status);
array_pop( $children);
}
echo "Completed in " . ( microtime( true) - $start) . " seconds.\n";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-wait.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57932
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57932&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57932&report=yes
Search -- http://master.php.net/manage/user-notes.php