php multi-thread
今天突然想看看PHP多线程的问题,发现很多人讲PHP的多线程其实是多进程,唉,破灭了!!!网上给PHP的模拟多线程提出了几种方案,下面仅摘录:
There are a few solutions, varying from "Hmmm, just about OK" through to "Poke out your eyes".
- Write your multithreaded code as a PHP extension. Probably the most supported, but you need to write in C (or another language supported for extensions).
- Spawn child processes onto the underlying OS, and read/write to their input/output with standard file handles. See popen for one route in, or PCNTRL. Reasonable, and you can use PHP from the command line.
- Make other HTTP requests to yourself via CURL or similar, thus piggybacking on your web servers multi-processing capacity. Keeps all your code "web like", but runs the risk of irate support developers tracking you down and breaking thumbs.