Claudio Ferraro
Claudio Ferraro

Reputation: 4721

How to execute a curl_exec every 10 seconds and collect the results when finished

Hello is the PHP: curl_multi_select function suitable to execute 1 curl_exec every 10 seconds ? I wanna to execute a culr_exec every 10 seconds and collect the results when finished. I cannot figure out how to start.

Upvotes: 1

Views: 504

Answers (1)

Chris Rasco
Chris Rasco

Reputation: 2731

I'm leaning towards thinking curl_multi_select() is not what you want to use here. From the docs:

int curl_multi_select ( resource $mh [, float $timeout = 1.0 ] )

Blocks until there is activity on any of the curl_multi connections.

mh - A cURL multi handle returned by curl_multi_init().

timeout - Time, in seconds, to wait for a response.

curl_multi_init() is designed for "the processing of multiple cURL handles in parallel", which is not what you are looking for.

If you need process a curl_exec() every 10 seconds you have a few options:

  • Use a scheduling tool to execute your script every 10s and store the data. (cron maybe)
  • Write a wrapper script in bash or python you run manually that kicks off a php script every 10s.

You could do the latter in PHP, but you'll have to increase your max execution time as you'll hit that relatively quickly.

Upvotes: 1

Related Questions