note 116980 added to class.pool
| From: | olavk | Date: | Mon, 30 Mar 2015 13:48:38 +0000 |
| Subject: | note 116980 added to class.pool | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202080@lists.php.net to get a copy of this message | ||
Simple example with Collectable (basically Thread meant for Pool) and Pool
<?php
class job extends Collectable {
public $val;
public function __construct($val){
// init some properties
$this->val = $val;
}
public function run(){
// do some work
$this->val = $this->val . file_get_contents('http://www.example.com/', null, null, 3, 20);
$this->setGarbage();
}
}
// At most 3 threads will work at once
$p = new Pool(3);
$tasks = array(
new job('0'),
new job('1'),
new job('2'),
new job('3'),
new job('4'),
new job('5'),
new job('6'),
new job('7'),
new job('8'),
new job('9'),
new job('10'),
);
// Add tasks to pool queue
foreach ($tasks as $task) {
$p->submit($task);
}
// shutdown will wait for current queue to be completed
$p->shutdown();
// garbage collection check / read results
$p->collect(function($checkingTask){
echo $checkingTask->val;
return $checkingTask->isGarbage();
});
?>
----
Server IP: 72.52.91.14
Probable Submitter: 90.190.224.150
----
Manual Page -- http://php.net/manual/en/class.pool.php
Edit -- https://master.php.net/note/edit/116980
Del: integrated -- https://master.php.net/note/delete/116980/integrated
Del: useless -- https://master.php.net/note/delete/116980/useless
Del: bad code -- https://master.php.net/note/delete/116980/bad+code
Del: spam -- https://master.php.net/note/delete/116980/spam
Del: non-english -- https://master.php.net/note/delete/116980/non-english
Del: in docs -- https://master.php.net/note/delete/116980/in+docs
Del: other reasons-- https://master.php.net/note/delete/116980
Reject -- https://master.php.net/note/reject/116980
Search -- https://master.php.net/manage/user-notes.php