php pthreads线程没有看到外部类

时间:2016-03-10 12:18:44

标签: php multithreading pthreads

问题是pthread的线程无法看到某些类,或者我可能不知道加载它们的正确方法。这是测试代码:

require_once('1/class.php');
require_once('1/geoip2.phar');
use GeoIp2\Database\Reader;


$t = new Test();
$t->start();

那就是class.php:

require_once('geoip2.phar');
use GeoIp2\Database\Reader;

class Test extends Thread{
    private $reader;

    public function __construct(){

        $this->reader = new Reader('C:\\users\\alex\\desktop\\temp\\GeoLite2-Country.mmdb');
    }

    public function run(){

        //$reader = new Reader('C:\\users\\alex\\desktop\\temp\\GeoLite2-Country.mmdb');
        //$ip = gethostbyname('');
        $record = $this->reader->country('127.0.0.1');
        //print_r($record);
        echo trim($record->country->name);
    }
}

错误信息是:

PHP Fatal error:  Uncaught Error: Class 'GeoIp2\Database\Reader' not found in C
\Users\bb\Desktop\temp\1\class.php:12
Stack trace:
#0 [internal function]: Test->run()
#1 {main}
  thrown in C:\Users\bb\Desktop\temp\1\class.php on line 12

那么如何将外部类添加到线程?谢谢!

0 个答案:

没有答案