Esempio n. 1
0
        /*
         * resources never supported
         */
        $this->res = fopen("php://stdout", "w");
        /*
         * tell the waiting process we have created symbols and fetch will succeed
         */
        $this->notify();
        sleep(2);
        /*
         * wait for waiting process to fetch symbols
         */
        $this->wait();
    }
}
$thread = new Fetching();
$thread->start(true);
/*
* we just got notified that there are symbols waiting
*/
foreach (array("sym", "arr", "obj", "objs", "res") as $symbol) {
    printf("Thread::fetch(%s): ", $symbol);
    $fetched = $thread->{$symbol};
    if ($fetched) {
        switch ($symbol) {
            /*
             * we need to manually serialize objects here
             */
            case "objs":
                print_r(unserialize($fetched));
                break;
Esempio n. 2
0
         */
        $this->res = fopen("php://stdout", "w");
        /*
         * tell the waiting process we have created symbols and fetch will succeed
         */
        $t = $this;
        $this->synchronized(function () use($t) {
            $t->notify();
        });
        /* wait for the process to be finished with the stream */
        $this->synchronized(function () use($t) {
            $t->wait();
        });
    }
}
$thread = new Fetching();
$thread->start();
$thread->synchronized(function ($me) {
    $me->wait();
}, $thread);
/*
* we just got notified that there are symbols waiting
*/
foreach (array("sym", "arr", "obj", "objs", "res") as $symbol) {
    printf("\$thread->%s: ", $symbol);
    $fetched = $thread->{$symbol};
    if ($fetched) {
        switch ($symbol) {
            /*
             * manual unserialize
             */
Esempio n. 3
0
        $this->obj = $obj;
        /*
         * will always work
         */
        $this->objs = serialize($this->obj);
        /*
         * nooooooo
         */
        $this->res = fopen("php://stdout", "w");
        /*
         * tell the waiting process we have created symbols and fetch will succeed
         */
        $this->notify();
    }
}
$thread = new Fetching();
/*
* You cannot start synchronized, because the run method will attempt to acquire the thread lock in order to manipulate members
*/
$thread->start();
/*
* Wait for the thread to tell us the members are ready
*/
$thread->wait();
/*
* we just got notified that there are symbols waiting
*/
foreach (array("sym", "arr", "obj", "objs", "res") as $symbol) {
    printf("\$thread->%s: ", $symbol);
    $fetched = $thread->{$symbol};
    if ($fetched) {