Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Wez Furlong's Blog:
Multiplexing ("Ask a Guru")
May 09, 2005 @ 11:56:14

Wez Furlong has an interesting new post on his weblog today with an answer to a question I see asked at least once a week - "Is there a way to do a form of threading in PHP?".

His simple answer? "No, but why do you need to?" People often assume that you need to fork or spawn threads whenever you need to do several things at the same time - and when they realize that PHP doesn't support threading they move on to something less nice, like perl. The good news is that in the majority of cases you don't need to fork or thread at all, and that you will often get much better performance for not forking/threading in the first place.

He continues on with an example about checking to see if a set of hosts are still up and running. Now, normally, using an fsockopen, we'd have to wait for it to return, but he suggests the PHP5 stream_socket_client() function that allows you to be free to start other connections while checking the results from the open ones. Pretty handly little feature - I wonder how many other little tricks there are of this type that PHP5 makes possible...

tagged:

Link:


Trending Topics: