Jump to content

php multithreading


bluetoother

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...