If my_func reads a URL and you just don't want it to take longer than a given timeout period, if you use the right URL functions, you should be able to specify that timeout and have the call fail if it takes longer than that.
If you were using cURL, you could use curl_multi_exec to get this behavior somewhat manually, or just specify the timeout and then the function can return false.
Example:
function my_func($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // timeout after 10 seconds
// .. set other options as needed
$result = curl_exec($ch);
if ($result === false) {
// timeout or other failure
return false;
}
}
Now the function won't run longer than roughly 10 seconds due to the timeout. You can also use curl_errno() to check for a timeout:
if (curl_errno($ch) == 28) {
// timeout was exceeded
}