Is it possible to implement event driven program in PHP?
Something like javascript.
As an example, try to open a socket(open_socket) and execute some other command(do_something_else) instead of waiting for the success response of socket request.
After getting the success response execute 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();
There is only a single thread in PHP. Therefore doing something useful whilst waiting for some event is not possible in PHP.
Some workarounds are available but probably not very reliable – especially not when you plan to write portable code. I would assume the workarounds are risky since the language does not have a concept of concurrency. It’s therefore probably best to write multi-threaded code in another language (Java, Scala, …) and use PHP just for displaying the prepared results (if using PHP at all for such problems).