I have 2 files (data1.php & data2.php) which fetch data through CURL. I have included these files in another page like index.php. One of these files (data1.php) sometimes takes too much time and hangs the page. I would like to know if there is a way which can check the load time of data1.php. If load time exceeds say 8 seconds, then it stops execution of data1.php and loads data2.php instead.
The data1.php often hangs, but is more relevant to the website, so it needs to be there. But when it hangs I want the page to display something closely relevant so data2.php. I tried calculating start & stop time with microtime()
but since the page hangs, it does not solve the issue.
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
How can I calculate loading time of data1.php amd if it takes more time then automatically stop its execution and load data2.php instead?