php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72528 Composer autoload not working on child threads
Submitted: 2016-06-30 17:46 UTC Modified: 2021-02-03 12:36 UTC
Votes:19
Avg. Score:4.5 ± 0.8
Reproduced:15 of 15 (100.0%)
Same Version:6 (40.0%)
Same OS:5 (33.3%)
From: tales dot augusto dot santos at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: pthreads (PECL)
PHP Version: 5.6.23 OS: Ubuntu 14.04.4 LTS
Private report: No CVE-ID: None
 [2016-06-30 17:46 UTC] tales dot augusto dot santos at gmail dot com
Description:
------------
I'm starting a project that uses pthreads to do jobs in parallel. The method \Thread::run is executed in a new context and don't share the autoload previously included at very begining of the script. The solution for that is to require vendor/autoload.php inside that method and the thread can make use of composer autoloader normally. I'm using PHP5.6 with Pthreads 2.0.10 and for some reason the composer can't load the classes needed in the \Thread::runcontext. Inspecting the file vendor/composer/autoload_real.php I realize that composer tries to load the configuration from vendor/composer/autoload_static.php file if the PHP_VERSION_ID is greather than 50600 and HHVM_VERSION constant is not defined. Forcing false to this verification the composer will load the configuration from the autoload_[namespaces|psr4|classmap].php files normally and everything works like a charm. 

This issue already was reported to composer team which tell me to report to pthread maintainers.

https://github.com/composer/composer/issues/5482

Test script:
---------------
class MyThread extends \Thread
{
    public function run()
    {
        register_shutdown_function(function () {
            var_dump(error_get_last());
        });
        require 'vendor/autoload.php';
        $obj = new My\Namespace\Class;
    }
}

// sample.php
require 'vendor/autoload.php';

$thread = new MyThread;
$thread->start() && $thread->join();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-04 17:22 UTC] tales dot augusto dot santos at gmail dot com
Discussing with members of Composer project, we realize that this problem is related with static class members inside threads. A working demo that reproduce this issue can be found here https://github.com/tsantos84/static-members-pthread.
 [2021-02-03 12:36 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-02-03 12:36 UTC] cmb@php.net
The maintainer of PECL/pthreads has ceased its developement for
good reasons[1].  Consider to use PECL/parallel[2] instead.

[1] <https://github.com/krakjoe/pthreads/issues/929>
[2] <https://pecl.php.net/package/parallel>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 08:01:29 2024 UTC