parallel downloads in PHP
Asked Answered
P

5

8

I want to download (or simply file_get_contents) for 5 places. I wait say 1.2 sec for each that means in total 1.2X5=6 seconds. I want to save waiting time. I thought I could wait 1.3 sec is enough. How can I approach?

Piliferous answered 28/10, 2010 at 18:37 Comment(4)
I do not understand. Do you want to download something in your script, or offer something for download? Then I don't understand what you want to do with the timingBighead
I think he wants his script to download 5 files in parallel.Act
can you execute command line programs?Bighead
@Bighead never mind timing. Yes I can execute but wont prefer any wayPiliferous
K
8

You can use the curl_multi_* functions to achieve parallel downloads.

Kelseykelsi answered 28/10, 2010 at 18:52 Comment(0)
V
2

this is possible but only by creating multiple threads outside PHP

With PHP scripts run in a single thread, meaning that it can only do 1 task at a time, the only way you can do this with PHP is by creating / using an external application installed / placed on your server and using exec to do this and waiting for a response from the exec, or using the fork_* functions to be able to dip and dive in and out of threads.

Vins answered 28/10, 2010 at 18:54 Comment(0)
X
1

To get you started you can run the downloads in parallel by forking them into the background using php's popen: http://www.php.net/manual/en/function.popen.php

Xiomaraxiong answered 28/10, 2010 at 18:51 Comment(0)
N
1

The curl_multi functions can be used for this purpose. Sample code is available in this repository.

https://github.com/amirreza-noori/PHP-multi-connection-downloader/

Nachison answered 6/7 at 20:40 Comment(0)
T
0

http://code.google.com/p/multicurl-library/

btw. you're looking for non blocking connections.

Taveda answered 28/10, 2010 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.