In PHP I have seen that if a certain process or function isn’t completed then the entire application which includes that function get delayed due to that.
Say there is a search function which returns lots of result which includes more than 20 functions. An “x” function is taking too much time, hence the result page is getting delayed due to that. My question is how do I fix a time limit to “X” function, say 2 seconds, and if it isn’t complete within that time then “X” function should be skipped.
Is there any way to do that or better?
So, if you’re talking about
file_get_contents(why didn’t you say that right away?) you may specify a timeout using stream contexts:See HTTP context options.
If using curl use
curl_setoptforCURLOPT_TIMEOUT.This will set timeout to ten seconds.