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 9119599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:26:05+00:00 2026-06-17T05:26:05+00:00

Part of the PHP web app I’m developing needs to do the following: Make

  • 0

Part of the PHP web app I’m developing needs to do the following:

  1. Make an AJAX request to a PHP script, which could potentially take from one second to one hour, and display the output on the page when finished.
  2. Periodically update a loading bar on the web page, defined by a status variable in the long running PHP script.
  3. Allow the long running PHP script to detect if the AJAX request is cancelled, so it can shut down properly and in a timely fashion.

My current solution:

  • client.php: Creates an AJAX request to request.php, followed by one request per second to status.php until the initial request is complete. Generates and passes along a unique identifier (uid) in case multiple instances of the app are running.
  • request.php: Each time progress is made, saves the current progress percentage to $_SESSION["progressBar"][uid]. (It must run session_start() and session_write_close() each time.) When finished, returns the data that client.php needs.
  • status.php: Runs session_start(), returns $_SESSION["progressBar"][uid], and runs session_write_close().

Where it falls short:

My solution fulfills my first two requirements. For the third, I would like to use connection_aborted() in request.php to know if the request is cancelled. BUT, the docs say:

PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush().

I could simply give meaningless output, but PHP must send a cookie every time I call session_start(). I want to use the same session, BUT the docs say:

When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless of if the current session id is identical to the one being set.

My ideas for solutions, none of which I’m happy with:

  • A status database, or writing to temp files, or a task management system. This just seems more complicated than what I need!
  • A custom session handler. This is basically the same as the above solution.
  • Stream both progress data and result data in one request. This solves everything, but I would essentially be re-implementing AJAX. That can’t be right.

Please tell me I’m missing something! Why doesn’t PHP know immediately when a connection terminates? Why must PHP resend the cookie, even when it is exactly the same? An answer to any of these questions will be a big help!

My sincere thanks.

  • 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-06-17T05:26:06+00:00Added an answer on June 17, 2026 at 5:26 am

    Why not set a second session variable, consisting of the unique request identifier and an access timestamp, from status.php.

    If the client is closed it stops getting updates from status.php and the session variable stops being updated, which triggers a clean close in request.php if the variable isn’t updated in a certain amount of time.

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

Sidebar

Related Questions

The following is a part of a bigger PHP script which adds or disables
In my (PHP) web app, I have a part of my site that keeps
I have been asked to re-develop an old php web app which currently uses
Part of our web app has a little Ajax method that will load a
I'm developing my first web-based app (I guess you could call it that), but
I am following the instructions on this page to create a PHP script which
I'm currently re-developing a fairly large-scale PHP web application. Part of this redevelopment involves
I've been taken onboard to work on a PHP-based web application. One part of
In part of my PHP application, I need to make an REST style API
I have a few issues with the following php functions (part of a bigger

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.