|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: shyxingang at 126 dot com
New email:
PHP Version: OS:


 [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: Tue Jan 25 09:03:34 2022 UTC