I make an AJAX POST request to a PHP script on my server. That script in turn makes a GET request to a php script on an external server to check the contents of a text file. However, it takes a very long time to come back with a result. Why is the case?
AJAX Post Request to Script on my server
session_start();
$fileName = $_POST['textFile'];
$result = file_get_contents($_SESSION['serverURL']."fileReader.php?textFile=$fileName");
echo $result;
GET Request to a script on different server
$fileName = $_GET['textFile'];
if (file_exists('text/'.$fileName.'.txt')) {
$lines = file('text/'.$fileName.'.txt');
echo $lines[sizeof($lines)-1];
}
else{
echo 0;
}
These are very simple scripts and its only checking a very small text file, so why does it take so long?
I am making other AJAX request on my site but these surely can’t be causing a problem. Having said this, the returned value of that text file always co-incides with the completion of another AJAX request which initiates a script that takes a while to complete on my server, but how would these effect each other?! They shouldn’t right?
You don’t have to take the route over HTTP to get the last line of a file. Why don’t you stay inside the file system and use a function like that to retrieve the last line: