PHPDaemon\Examples\ExampleWithMySQLRequest::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();
            $this->wakeup();
            // wake up the request immediately
        });
        $job('select', function ($name, $job) {
            // registering job named 'select'
            $this->appInstance->sql->getConnection(function ($sql) use($name, $job) {
                if (!$sql->isConnected()) {
                    $job->setResult($name, null);
                    return null;
                }
                $sql->query('SELECT 123, "string"', function ($sql, $success) use($job, $name) {
                    $job('showdbs', function ($name, $job) use($sql) {
                        // registering job named 'showdbs'
                        $sql->query('SHOW DATABASES', function ($sql, $t) use($job, $name) {
                            $job->setResult($name, $sql->resultRows);
                        });
                    });
                    $job->setResult($name, $sql->resultRows);
                });
                return null;
            });
        });
        $job();
        // let the fun begin
        $this->sleep(5, true);
        // setting timeout
    }
ExampleWithMySQLRequest