所以我使用pthreads来异步写入MongoDB(我想尝试React但它不支持PUT和POST HTTP方法)但是在使用Thread类时我遇到了一个问题.出于某种原因,当我将代码放在__construct()和run()方法中时,执行它会给出一个错误,即找不到某些类.我正在使用相同的Composer自动加载器,并且在我不使用Threading API时没有问题.关于它为什么会发生的任何想法?
<?PHP class WriterThread extends Thread { private $validator; private $pathResolver; private $fileUpload; private $fileSystem; public $result; public function __construct($folderPath,$mongoFS) { try { $this->validator = new MongoFileSystemValidator(1024 * 1024 * 1024 * 2); //the maximum size set to 2GB // Simple path resolver,where uploads will be put $this->pathResolver = new FileUpload\PathResolver\Simple($folderPath); // The machine's filesystem $this->fileSystem = new MongoFS($mongoFS); // FileUploader itself $this->fileUpload = new FileUpload\FileUpload($_FILES['files'],$_SERVER); //var_dump(get_declared_classes()); $this->fileUpload->setPathResolver($this->pathResolver); $this->fileUpload->setFileSystem($this->fileSystem); $this->fileUpload->addValidator($this->validator); } catch (Exception $e) { echo $e->getMessage(); } } public function run() { $this->result = $this->fileUpload->processAll(); } }
所以PHP输出一个错误,说明在我应该加载的时候找不到我在线程中使用的一个类实例的类定义.如果我使用include或require手动导入它,代码会输出另一个错误,指出我正在尝试访问非对象类型变量的方法.