php.net |  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
 [2013-01-31 16:51 UTC] neu dot markus at web dot de
Description:
------------
require('./template/index.php');

Test script:
---------------
index.php:
<?php
require('./function/main/main.php');
?>

function/main/main.php:
<?php
$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;
require('./function/pthread.php');
for($i = 0; $i < 10; $i++)
{
	echo BuildThread(1, $array);
}
function func1($data)
{
	$data2 = $data[1];
	$rand_key = array_rand($data2);
	$page = "";
	require('./template/index.php');	
	return $page;
}
function func2()
{
	return null;
}
?>

function/pthread.php
<?php
error_reporting(E_ALL);
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);
		}

		unset($this->data);

    }

}
function BuildThread($func, $data)
{
	$t = microtime(true);
	$g = new MyThread($func, $data);
	/* starting synchronized */
	if($g->start())
	{
		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;
		}
		else
		{
			printf(" and %f seconds to <font style=\"color:red;\">failed</font>\n", microtime(true)-$t);
		}
	}
	unset($data);
}
?>

template/index.php
<?php

$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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

File: Test.php
<?php
error_reporting(E_ALL);

class TestIncludes extends Thread {
    public function run() {
        require_once("Include.php");
        if (class_exists("Included")) {
            $c = new Included(12);
            var_dump($c);
        }
    }
}

$t = new TestIncludes();
$t->start();
?>

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC