Hello
I have a PHP application which needs to invoke several URLs using file_get_contents
each URL will return its own set of values
Is there a way to spawn multiple threads in PHP, letting each one handle its own URL with file_get_content?
Otherwise, doing it sequencially will take a long time, where I have to wait for one call of file_get_content to finish before the next can begin
if this is possible, I would apprciate a link on the subject for reading
multi threading in PHP
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Via the pcntl extension (unix only, although I have seen Windows CGYWIN ports), PHP supports forking and other fun stuff.
I can think of two solutions .. which to use depends on which version of PHP you're using ..
1. http://uk.php.net/manual/en/function.cu ... i-exec.php .. CURL-Multi can get lots of pages at once. PHP5 only though. And there's practically no documentation.
2. Use fsockopen() to open some sockets to the servers you're getting data from, set them all to non-blocking with stream_set_timeout(), and write the HTTP requests yourself.
1. http://uk.php.net/manual/en/function.cu ... i-exec.php .. CURL-Multi can get lots of pages at once. PHP5 only though. And there's practically no documentation.
2. Use fsockopen() to open some sockets to the servers you're getting data from, set them all to non-blocking with stream_set_timeout(), and write the HTTP requests yourself.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
php5 has curl_multi_* functions 
Here is an example of how to use it: http://blog.bitflux.ch/archive/2005/10/ ... feeds.html.
(On php4 i simply have a cronjob that fetches the complete load every 30mins and stores the fetched stuff in a database).
Here is an example of how to use it: http://blog.bitflux.ch/archive/2005/10/ ... feeds.html.
(On php4 i simply have a cronjob that fetches the complete load every 30mins and stores the fetched stuff in a database).