在PHP中实现事件驱动程序是否可能?
就像JavaScript一样。
例如,尝试打开socket(open_socket)
并执行其他command(do_something_else)
,而不是等待套接字请求的成功响应。
在获得成功响应后执行callback_execute
。
//--------------------------------------------------------------------
public function open_socket(){
$this->socketResource = fsockopen($this->nodeIp,$this->portNumber);
}
public function callback_execute(){
fputs($this->socketResource,$command);
}
public function do_something_else{ xxxxx }
//--------------------------------------------------------------------
Non_blocking_function($obj->open_socket(),$obj->callback_execute());
$obj->do_something_else();