foreach ($arr as $k => $v)
{
$r = my_func($v);
$new[$k] = $r;
}
How do you do it so that $r will return false if my_func() takes more than 10 secs to execute, else (if it took less than 10 secs) it will return true;
Additional info: my_func() actually reads a URL, sometimes it takes to long. I want it to return false if it takes more than 10 secs.
You cannot limit execution time by function in PHP. However, do not despair: if as you mentioned your function reads URL, you could use curl extension, which has options set options via curl_setopt, as following:
CURLOPT_TIMEOUT The maximum number of seconds to allow cURL functions to execute.
CURLOPT_CONNECTTIMEOUT The number of seconds to wait while trying to connect.
Using these you could limit the actual time spent on the URL processing with curl.
You could also use http extension which also allows you to do http connections and has timeout options.
Finally, you could use context options to file_get_contents: