So I'm using pthreads for async writing to MongoDB (I wanted to try React but it doesnt support PUT and POST HTTP methods) but I encounterd a problem when using the Thread class. For some reason, when I put code inside the __construct() and run() methods, executing it gives an error that certain classes aren't found. I'm using the same Composer autoloader and have no problems when I'm not using the Threading API. Any ideas as to why it is happening?
<?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();
}
}
So PHP outputs an error stating that a class definition of one of the class instances I'm using inside the thread is not found when it's supposed to be loaded. And If I manually import it with include or require, The code outputs another error stating that I'm trying to access a method of a non-object type variable.