Languages :: PHP :: threading in php |
|||
| By: sergey |
Date: 04/10/2006 22:32:33 |
Points: 20 | Status: Answered Quality : Excellent |
|
is it possible to use multi-threading in php? something like fork() function in C++. i primarily need this for http requests and database queries. |
|||
| By: VGR | Date: 05/10/2006 14:25:32 | Type : Answer |
|
| kind-of there is no fork() nor multithreading in PHP per itself, but you've the tools available to do asynchronous data handling over sockets ; given you can do a system() or exec() with a fork command... if not on Windows... it could be feasible. The main jewel is the stream_select() function. You've an explanation of what I'm suggesting (for PHP5) here on Wes Furlong's site For PHP4, it's done using sockets in stead of streams. Nice idea. Now that we speak of PHP5, it is NOT multithread-enabled, but you can duplicate a process with the PCNTL extension, namely the pcntl_fork() function. The is also in the CVS tree an experimental extension named php_threads which, as you already assumed, makes those functions available at your own risk & peril ;-) * thread_start * thread_include * thread_set * thread_get * thread_mutex_init * thread_mutex_destroy * thread_lock * thread_lock_try * thread_unlock As you can guess, there are many people thinking about multithreading in PHP, so an other extension is available, but with no documentation, althought there is a demo page ! Regards |
|||
| By: sergey | Date: 05/10/2006 15:32:39 | Type : Comment |
|
| thank you. thats exactly that i searched. | |||
| By: VGR | Date: 05/10/2006 19:07:06 | Type : Comment |
|
| you're welcome. If ever you've some time to share later, I am interested in what you will come up with as a multithreading viable solution ;-) |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








