Is there a realistic way of implementing a multi-threaded model in PHP whether truly, or just simulating it. Some time back it was suggested that you could force the operating system to load another instance of the PHP executable and handle other simultaneous processes.
The problem with this is that when the PHP code finished executing the PHP instance remains in memory because there is no way to kill it from within PHP. So if you are simulating several threads you can imagine whats going to happen. So I am still looking for a way multi-threading can be done or simulated effectively from within PHP. Any ideas?
using threads is made possible by the pthreads PECL extension
http://www.php.net/manual/en/book.pthreads.php
Multi-threading is possible in php
Yes you can do multi-threading in PHP with pthreads
From the PHP documentation:
Simple Test
First Run
Second Run
Real World Example
Threading isn't available in stock PHP, but concurrent programming is possible by using HTTP requests as asynchronous calls.
With the curl's timeout setting set to 1 and using the same session_id for the processes you want to be associated with each other, you can communicate with session variables as in my example below. With this method you can even close your browser and the concurrent process still exists on the server.
Don't forget to verify the correct session ID like this:
startprocess.php
process1.php
verifysession.php
closeprocess.php
How about pcntl_fork?
check our the manual page for examples: PHP pcntl_fork
The Thread class is available since PECL pthreads ≥ 2.0.0.
why don't you use popen?