78177

PHP: continue after output is complete

Question:

First, I am not looking for ignore_user_abort. Instead, I look for a function to finalize the output and send the document to the user. After that, I'd like the php script to do additional process which takes another seconds without effects for the user, only background process.

There is no reason for the user to wait for this to be completed, too. The output is ready for catch up before already. Does PHP provide a feature for closing the connection to the user, but remain for a while on the server to complete the work?

Answer1:

One of the best features of php-fpm You is fastcgi_finish_requests(). This will finish the session for the client side and continue the process at serverside. It's also best use-case for messaging as an alternative for queque or delayed processing by cron.

However, it's restricted to php-fpm!

Answer2:

You should split your work into 2 files, (The one with the initial processing, which produces output), and the second, heavier one which takes several more seconds but should not make the user to wait until its completion.

Then, have the browser call it with either Ajax or a hidden iframe.

You could even have the second script return a success/fail notice and catch that with JavaScript to notify the user, without affecting his actual initial output.

Answer3:

looks like what you want is some ajax stuff. if you send the response back to the user, the script will end. but using javascript you can start an ajax call to another php script that will not change anything for the user.

Answer4:

you could try using curl(); to ping localhost and trigger another script execution to run any extra tasks you have.

Answer5:

Once the script has been run, add an entry into a queue table. Then run a cron job to process the queue, locking the record and then deleting them as they get processed, so if your crons overlap they don't do the same job twice.

Recommend

  • Best practice to handle default server and ip forwarding in nginx
  • How to enable the Virtual Directory Support php?
  • Datagridview Change cell color of non empty cell
  • application closes after closing interstitial ad
  • CakePHP 3 losing Auth Session
  • php cannot connect to mysql in docker-compose
  • “class template has already been declared as a non-class template”
  • Laravel routes not found on nginx
  • Must EOT be at the bebinning in the line?
  • Debug PHP in Atom While Using Vagrant
  • Regex for incomplete lines within known start and end strings
  • Dependable views in Ember
  • dismiss Progress Dialog in another Activity … Android
  • How to wait for all async tasks to finish in Node.js?
  • What is the equivalent of Android permissions in iOS development? [duplicate]
  • Avoid registering duplicate broadcast receivers in Android
  • Java making confirming exit
  • Better Indy for Dephi 2007
  • Splash Screen will not display
  • Compare struct to a constant in C
  • Activation Function choice for Neural network
  • what makes a request a new request in asp.net C#
  • SQLite connection strategies
  • Clear activity stack before launching another activity
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Does Mobilefirst provide a provision to access web services directly?
  • How can I extract results of aggregate queries in slick?
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Q promise. Difference between .when and .then
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Display Images one by one with next and previous functionality
  • Do create extension work in single-user mode in postgres?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How to load view controller without button in storyboard?