1

I was wondering if there was a way to return a page to a user before a specific process is complete in PHP. I've done this in C++ before using asynchrony on a client-only application, but this is something I've never tried. Consider the following hypothetical process:

  1. The user logs onto a website and presses a button to backup a large file to another server. The website is being served by PHP
  2. The request to backup the server goes to PHP and begins executing. The process may take a long time and needs to start immediately, but we don't want the user to sit there waiting for a response from the server. Think HTTP 202.

I was wondering more specifically if there's a way to do this in the function that is called by the request without needing to put a task in a specific cache of sorts to be run by something like a cron.

Kirkland
  • 798
  • 1
  • 8
  • 20
  • 1
    Check out this question it should help you http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications – Derek Dec 23 '16 at 20:47
  • Wouldn't the threads have to join before the function can return? So if a framework such as Laravel were in use even though it does start a new thread, wouldn't that thread have to rejoin the main thread before returning or else result in a zombie process? – Kirkland Dec 23 '16 at 20:52
  • So the web user is just initiating a process between two other machines? Or is the user uploading a large file from his/her machine to the server? – ivanivan Dec 23 '16 at 20:55
  • Let's say that the user calls a function via a web request that will take 40 minutes to complete. Instead of having the user wait, we want to start the process but still have the function return a view to the user before it finishes to keep the UX fast. Let's say that the process is calling a PHP endpoint on another server to copy over a file. So use makes a request to the server, the server makes a request to another server that will take 40 minutes to complete, say a file transfer. – Kirkland Dec 23 '16 at 21:02
  • Another way to look at this is trying to mimic C# async methods in a ASP.NET MVC 5 application in PHP. – Kirkland Dec 23 '16 at 21:16

0 Answers0