visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: threading in php


By: sergey Russia  Date: 04/10/2006 22:32:33  English  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 English  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 English  Type : Comment
thank you. thats exactly that i searched.
By: VGR Date: 05/10/2006 19:07:06 English  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

EContact
browser fav
page generated in 337.729930 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page