PHPDaemon\Examples\ExampleWithMongoRequest::init PHP Method

init() public method

Constructor.
public init ( ) : void
return void
    public function init()
    {
        $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) {
            // called when job is done
            $job->keep();
            // prevent cleaning up results
            $this->wakeup();
            // wake up the request immediately
        });
        $collection = $this->appInstance->mongo->{'testdb.testcollection'};
        $collection->insert(['a' => microtime(true)]);
        // just pushing something
        $job('testquery', function ($name, $job) use($collection) {
            // registering job named 'testquery'
            $collection->findOne(function ($result) use($name, $job) {
                // calling Mongo findOne
                $job->setResult($name, $result);
            }, ['sort' => ['$natural' => -1]]);
        });
        $job();
        // let the fun begin
        $this->sleep(1, true);
        // setting timeout
    }
ExampleWithMongoRequest