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

  • SEARCH
  • Home
  • 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 7578583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:28:03+00:00 2026-05-30T17:28:03+00:00

The PHP script takes 25 seconds to complete (for 1 person) and probably longer

  • 0

The PHP script takes 25 seconds to complete (for 1 person) and probably longer with high traffic. I don’t want the browser to time out (PHP won’t – I set_time_limit(0);).

Can someone provide sample code on how to make sure the browser doesn’t time out (or else explain in detail what to do)? What’s the best method? Ajax?

Thanks.

EDIT:

Brian Graham says, “Once javascript starts an ajax request, it runs until it finishes, quits or errors. As far as I know, it should even do this if the user leaves the page.”

So, could I simply call the long PHP script via Ajax, and then it would run for however long is needed without ever timing out (even if nothing was returned by the script)?

  • 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-30T17:28:04+00:00Added an answer on May 30, 2026 at 5:28 pm

    That really depends on what your script is doing and what it’s sending back, but if you can use AJAX that would be the way to go. Not only would it let you run the request for a long period of time, but wouldn’t tie up the browser leaving the user free to continue using the current page until the request is done.

    The best way to implement something like this that I’ve found is to set ignore_user_abort and turn off the time limit. This way you can let the script run in the background. This way the script can continue to run while the user browses your site. They don’t even have to stay on the same page. So you fire off the request with AJAX to start it up. Have a loop in that script that updates the progress to the user’s session.

    ini_set('session.use_cookies', 0); //don't spam the user with cookies for each session_start()
    while( ... ) {
        session_start();
        //update status to the user's session
        session_write_close();
        //sleep or whatever
    }
    

    Obviously this doesn’t have to be a loop. You can simply close the session before you start processing information, then open it, set a status, and close it again. Only one script can access a user’s session at a time, so you need to make sure this process isn’t tying that up.

    Then all you need to do is make a script that runs on the pages of your site that lets the user know when whatever it is you’re doing is done and/or provides them the file/output/etc.

    This frees up the user to continue browsing your site while your script is running and doesn’t force them to sit on a single page staring at a loading indicator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to measure how long a specified part of my php script takes,
I want to put the number of seconds a search script takes to search
<?php // Execute a shell script $dump = shell_exec('bigfile.sh'); // This script takes some
I have a php pipe script that receives an email, takes an attached *.csv
I've got a php script. Most of the time the script returns html, which
I have a PHP script which opens a socket connection(using fsockopen) and takes about
I have a php page that takes 2.8 seconds to render. The page contains
I got this php script that generates reports that take 20 to 30 seconds
I have an ajax call to one php script via jquery but it takes
I'm trying to make a PHP script that will take a potentially infinite number

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.