|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66349 can't use gobal variables in multi thread
Submitted: 2013-12-25 11:23 UTC Modified: 2013-12-25 13:02 UTC
From: shyxingang at 126 dot com Assigned:
Status: Not a bug Package: pthreads (PECL)
PHP Version: 5.5.7 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
37 - 12 = ?
Subscribe to this entry?

 [2013-12-25 11:23 UTC] shyxingang at 126 dot com
From manual page:

with pthreads version:  pthreads-0.0.45

Test script:

class Buy extends Thread{
    protected $name;

    public function __construct($name){
        $this->name = $name;
    public function run(){
        global $xxx,$tickPool;  
        echo $xxx."\n\n\n\n\n";

$tickPool = new SplQueue();
$xxx = "abcdefg";

$buyers = array();
    $buyers[$i] = new Buy("buyer_".$i);
foreach($buyers as $b){

Expected result:
can see the value of $xxx but not

Actual result:
$xxx is nothing


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-25 13:02 UTC]
-Status: Open +Status: Not a bug
 [2013-12-25 13:02 UTC]
That is intentional behaviour; it is not safe to allow multi-threaded access to global variables since there is no opportunity to implement safety during their manipulation, therefore no steps are taken to make globals available since they are not safe.

The solution is to set data you wish to share between contexts as a member of an object descended from pthreads where every thread that requires access has a reference to the data.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 18:03:33 2022 UTC