bluetoother Posted July 21, 2008 Share Posted July 21, 2008 hello iam writing a php script and want to it perform it's expected job faster.the script give a sequence of orders to run a function. function some_work($x){ //do $x job;}some_work(7625);some_work(8432);some_work(762545);some_work(843254);some_work(7542625);some_work(65428432); can i run these functions in a multithread mode to get faster execution ?know how ? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 21, 2008 Share Posted July 21, 2008 Multithreading isn't necessarily going to speed it up, it will only speed it up if the work is not CPU-bound. If the bottleneck is on the CPU then making more threads isn't going to make anything go faster. If the bottleneck is on memory or disk access then it might help.The normal way to create another process on Unix is to fork the process, creating an identical process that is running the same code.http://www.php.net/manual/en/function.pcntl-fork.phpThe two processes can use shared memory and signals to communicate with each other if necessary. Other than forking a new process though, there's not a lot you can do in a PHP script to run it in more than one thread. If the web server is multithreaded then it will run PHP in several threads, but if the web server isn't multithreaded already there's nothing you can do in a script to make it multithreaded. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.