Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 239811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:36:55+00:00 2026-05-11T20:36:55+00:00

I make an AJAX POST request to a PHP script on my server. That

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:36:55+00:00Added an answer on May 11, 2026 at 8:36 pm

    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:

    function fileGetLine($filename, $line) {
        if (!is_file($filename) || !is_readable($filename)) {
            // invalid file name or not readable
            return false;
        }
        if (!is_int($line)) {
            // invalid line number
            return false;
        }
        $lines = file($filename);
        $lineCount = count($lines);
        if ($line < 0) {
            // negative line number, count from end
            $line = $lineCount + $line;
        }
        if ($line < 0 || $line >= $lineCount) {
            // line number out of bounds
            return false;
        }
        return $lines[$line];
    }
    
    session_start();
    echo fileGetLine('text/'.basename($_POST['textFile']).'.txt', -1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 198k
  • Answers 198k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to specify parameter types in getMethod() invocation: method… May 12, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer So the basic problem here is that you have a… May 12, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer You can fix this by making B static: static class… May 12, 2026 at 7:31 pm

Related Questions

I make an AJAX request to a PHP script which returns a number from
I'm working at an app which would make a POST ajax request to a
I'm implementing a relatively simple autosave system and I'd like to do so using
Why was it decided that using XMLHTTPRequest for doing XML calls should not do

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.