php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69542 Unexpected collect result from Pool
Submitted: 2015-04-28 10:25 UTC Modified: 2017-04-02 15:31 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: djmon84 at gmail dot com Assigned:
Status: Not a bug Package: pthreads (PECL)
PHP Version: 5.6.8 OS: CentOs 6.6
Private report: No CVE-ID: None
 [2015-04-28 10:25 UTC] djmon84 at gmail dot com
Description:
------------
I'm using the last version of the package: 2.0.10
The "collect" method returns elements in wrong order, always overwrites the first result with the last result.

Test script:
---------------
class job extends Collectable
{
	public $val;

	public function __construct($val){
    	    $this->val = $val;
	}
	public function run(){
	    'started ' .$this->val . PHP_EOL;    
	    sleep(1);
	    'finished ' .$this->val . PHP_EOL;		
	    $this->setGarbage();
	}
}

$p = new Pool(1);

$tasks = array(
    new job('job1'),
    new job('job2'),
    new job('job3'),
    new job('job4'),
    new job('job5')
);

foreach ($tasks as $task)
    $p->submit($task);

$p->shutdown();

$p->collect(function($checkingTask){
   $checkingTask->val;
});

Expected result:
----------------
job1
job2
job3
job4
job5

Actual result:
--------------
job5
job2
job3
job4
job5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-02 15:31 UTC] tpunt@php.net
-Status: Open +Status: Not a bug
 [2017-04-02 15:31 UTC] tpunt@php.net
The collect method is not deterministic, and so it cannot be relied upon for retrieving data from a pool.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC