|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64117 require didnt work
Submitted: 2013-01-31 16:51 UTC Modified: 2013-01-31 18:06 UTC
From: neu dot markus at web dot de Assigned:
Status: Not a bug Package: pthreads (PECL)
PHP Version: 5.4.11 OS: Windows 7 64bit
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:
19 - 11 = ?
Subscribe to this entry?

 [2013-01-31 16:51 UTC] neu dot markus at web dot de

Test script:

$array = array();
$array[1][0][202][1][0] = 100;
$array[1][1][202][1][1] = 200;
$array[1][2][202][1][0] = 100;
$array[1][3][202][1][1] = 200;
$array[0][0][202][1][0] = 300;
$array[0][1][202][1][1] = 400;
for($i = 0; $i < 10; $i++)
	echo BuildThread(1, $array);
function func1($data)
	$data2 = $data[1];
	$rand_key = array_rand($data2);
	$page = "";
	return $page;
function func2()
	return null;

class MyThread extends Thread
	public $func;
	public $data;
	public $res;
	public function __construct($func, $data)
		$this->func = $func;
		$this->data = $data;

    public function run()
        //printf("%s is Thread #%lu\n", __CLASS__, $this->getThreadId());
		if($this->func == 1)
			$this->res = func1($this->data);
		elseif($this->func == 2)
			$this->res = func2($this->data);



function BuildThread($func, $data)
	$t = microtime(true);
	$g = new MyThread($func, $data);
	/* starting synchronized */
		printf("Request took %f seconds to start ", microtime(true)-$t);
		if ($g->join())
			printf(" and %f seconds to finish\n", microtime(true)-$t);
			return $g->res;
			printf(" and %f seconds to <font style=\"color:red;\">failed</font>\n", microtime(true)-$t);


$page = "Random key: ".$rand_key." <br />";


Expected result:
include or require from a Thread

Actual result:
Warning: require(./template/index.php): failed to open stream: No such file or 
directory in D:\localhost\htdocs\test\pthreads\function\main\main.php on line 24

Fatal error: require(): Failed opening required './template/index.php' 
(include_path='.;C:\php\pear') in 
D:\localhost\htdocs\test\pthreads\function\main\main.php on line 24


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-31 18:06 UTC]
-Status: Open +Status: Not a bug
 [2013-01-31 18:06 UTC]
See the following:

File: Include.php
class Included extends Stackable {
    public function run(){}

File: Test.php

class TestIncludes extends Thread {
    public function run() {
        if (class_exists("Included")) {
            $c = new Included(12);

$t = new TestIncludes();

There is no reason that including or requiring should not work, you could try 
giving the full path to the file. The example given is convoluted I must assume 
it to be a programming error.

Please try to post short examples that display behavior you are unsure of; when 
you think you have found a bug, try to write the simplest version of some code 
that displays the same behavior as the bug you have found. I understand in this 
instance that an additional file is required by nature, the examples I gave are 
fine to investigate the problem.

That aside, this isn't an advisable pattern to adopt, by executing 
require/include in a thread, you cost every thread you initialize the overhead 
of compiling the file you have requested inclusion of, a considerable waste. The 
code you are including should be written specifically for execution in this 
environment, using the objects provided, it should be included one time before 
any threads reference any of its object declarations thereby eliminating the 
overhead of inclusion and compilation in every thread.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 20 09:03:33 2022 UTC