Why not make an API return JSON and make an internal PHP request to that JSON? Some frameworks enable this functionality quite nicely (such as Laravel).
You can go down a couple levels lower than file_get_contents (which is just a wrapper for fopen/fread/fclose) and try with fsockopen to have access to a timeout parameter. Here is a sample function:
if ( ($response = http_get("www.mysite.com", "/something.php?something={command}", 15) ) !== false )
{
//Do something here with the $response
//Start by trimming the headers first ($response will contain "HTTP/1.1 200 OK" ... and/or other headers)
}
else
{
exit("HTTP Get failed");
}
Downside is : this is very low level. Unless your GET request will run something on the server and you don’t care for the response, you are better served using cURL or some other abstract library for this kind of queries.
You can control now your side of the timeout using the third argument of the http_get function. However, if the server times out while proccessing the request - you can’t really do much, no matter the function/library/client you use, except send another request upon server failure and hope for success.