php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75792 Class 'Threaded' not found
Submitted: 2018-01-10 13:18 UTC Modified: 2021-02-03 12:37 UTC
Votes:12
Avg. Score:4.3 ± 0.9
Reproduced:10 of 10 (100.0%)
Same Version:6 (60.0%)
Same OS:4 (40.0%)
From: imdad at neotericuk dot co dot uk Assigned: cmb (profile)
Status: Wont fix Package: pthreads (PECL)
PHP Version: 7.1Git-2018-01-10 (Git) OS: Ubuntu 16.04.3 LTS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-01-10 13:18 UTC] imdad at neotericuk dot co dot uk
Description:
------------
Here is my PHP version

$ php -v

PHP 7.1.12 (cli) (built: Jan 10 2018 13:11:41) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies



Here is the output if I grep the info

$ php -i  | grep -i thread

System => Linux pthread 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64
Configure Command =>  './configure'  '--prefix=/usr/local/php71/' '--with-pear' '--disable-short-tags' '--with-openssl' '--with-pcre-regex' '--with-zlib' '--enable-bcmath' '--with-curl' '--enable-exif' '--with-gettext' '--enable-intl' '--enable-mbstring' '--with-mysqli' '--enable-pdo' '--with-pdo-mysql' '--enable-soap' '--enable-simplexml' '--enable-xml' '--with-xmlrpc' '--with-xsl' '--enable-zip' '--enable-mysqlnd' '--enable-maintainer-zts' '--with-pthreads'
Thread Safety => enabled



But, when I run a PHP script from command line that has used Threads I get the below fatal error.

Fatal error: Class 'Thread' not found in /home/<my folder path>/test1.php on line 2





Test script:
---------------
<?php
$task = new class extends Thread
{
    private $response;

    function run()
    {
        $content = file_get_contents("http://google.com");
        preg_match("~<title>(.+)</title>~", $content, $matches);
        $this->response = $matches[1];
    }
};

$task->start() && $task->join();

var_dump($task->response); // string(6) "Google"


Expected result:
----------------
string(6) "Google"

Actual result:
--------------
Fatal error: Class 'Thread' not found in /home/<my folder path>/test1.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-12 23:08 UTC] a at b dot c dot de
You are installing the pthreads library from PECL?
 [2018-01-15 10:31 UTC] imdad at neotericuk dot co dot uk
No, it is compiled along with PHP it-self. Could that be an issue?
 [2021-02-03 12:37 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-02-03 12:37 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 Apr 24 15:01:30 2024 UTC