Alright although, I must agree with eis on this one. PHP probably isn't the best language to be doing this in, here's my suggestion...
First File:
//Write "1" to text file (loading.txt)
//Run secondary php file (loading.php) asyncronously
//I would suggest curl_post_async or exec(url)
//Start Connection
//Upon load finish write "0" to text file (loading.txt)
Here's a nice discussion about requesting a page without waiting for it to load:
php request url without waiting for response
Second File (loading.php):
$start=mktime();
while (true) {
if ("loading.txt" if value = 0) {
break;
else if (($start-mktime()) > MAX WAIT TIME) {
//Log as "slow-to-respond"
break;
}
}
You will prob need to modify your php.ini and set the max execution time accordingly.
Again I feel like this is kinda sloppy. I really would suggest using some other language.
Basically, right before you start the connection, you run this other php file which continues to loop until either 1. it reads from the loading.txt file that you've finished the connection OR 2. you're ready to log it as a "slow-to-respond" instance. In which case the 2nd php file ends and you've achieved your desired result.