The Stackable class

(PECL pthreads >= 0.36)

Introdução

Stackables are tasks that are executed by Worker threads. You can synchronize with, read, and write Stackable objects before, after and during their execution.

Sinopse da classe

Stackable {
/* Métodos */
final public boolean chunk ( long $size , boolean $preserve )
final public boolean isRunning ( void )
final public boolean isTerminated ( void )
final public boolean isWaiting ( void )
final public boolean lock ( void )
final public boolean merge ( mixed $from [, mixed $overwrite ] )
final public boolean notify ( void )
final public boolean pop ( void )
abstract public void run ( void )
final public boolean shift ( void )
final public mixed synchronized ( Closure $block [, mixed $... ] )
final public boolean unlock ( void )
final public boolean wait ([ string $timeout ] )
}

Índice

add a note add a note

User Contributed Notes 1 note

up
0
lein_urg at 163 dot com
8 months ago
How to give worker a class instance which has a resoure, such as database access class?

I found a way of that:
you just need to modify you class to extends Stackable, then add a empty run method, then modify all private methods to public method.

Example:
<?php
//old one
class db {
    private
$conn=NULL;
    public function
db($user,$pwd='',$db_name,$host='localhost',$_charset='utf8',$connectImediatly = false){   
       
$this->doConnect();
    }
   
    private function
doConnect($flag=false)
    {   
       
$this->conn = @mysql_connect($host,$user,$pwd,1) or die('A'.mysql_error());
       
$this->doselect($db_name,$this->charset);
    }
}

===>

<?
php
//new one , $db=new $db(...); $worker = new myworker($db);
//$db will work well in your worker
class db extends Stackable{
    private
$conn=NULL;
    public function
db($user,$pwd='',$db_name,$host='localhost',$_charset='utf8',$connectImediatly = false){   
       
$this->doConnect();
    }
   
    public function
doConnect($flag=false)
    {   
       
$this->conn = @mysql_connect($host,$user,$pwd,1) or die('A'.mysql_error());
       
$this->doselect($db_name,$this->charset);
    }
   
    public function
run(){
       
    }
}
To Top