0

I have made any possible attempt.

Context:

  1. shared hosting, no access to the shell
  2. any kill and exec PHP command disabled

Purpose

  1. start a long process in the background by a post form request
  2. update the background process state in a file
  3. possibly read from the browser on periodic intervals the progress state (not necessary)
  4. continue to use the user session in the same browser to do other things in the same website login pages
  5. kill the process if needed by sending a specific command. Since PHP kill functions are not available, the PHPP function that receive the request write a kill command on a file that is periodically read by the background process. If the kill comand is detected the background process end safely.

Solution 1: FORKING

  1. the request for stating the job is sent in a private login session by an ajax post request
  2. the starting PHP function forks itself. The parent is not waiting for the children ending and it flushes a JSON answer ("process_began") and exits
  3. the children continue in the background the process

The logic works, BUT

  1. the browser freezes itself waiting for the children to end as the forking procedure was not changing anything. I found around that this is because Apache considers the children as for the same request from the browser.
  2. if the killing procedure is called it is piped waiting for the children to end
  3. opening a different browser, for instance, the first Chrome the second IE, if the killing procedure is called by IE, it works properly, the background process is ended.

Solution 2: calling a second function that performs the long job with a PHP CURL request and a very short timeout (1s) so that the calling function is not waiting for the answer;calling and called functions are in the same server and controller

The logic works, but I have the same problems of solution 1. The browser freezes and waits for the long job to be completed. No other pages of the private login session are available in the meantime as well as the ajax kill request is piped.

How can I get the request of starting the long background making the browser not waiting for the response and the server accepting another request from the same user and browser? I believe that using web forms for sending long files for bulk uploads or long elaborations is a common need; does a solution really not exist for these cases? Thank you.

(I have not attached code because it seems to me more conceptual trouble related to the environment and web server logic rather than to the code that is correct, I don't have errors; in case of need I can anyway add some code).

fede72bari
  • 343
  • 5
  • 17
  • Have you read through https://stackoverflow.com/questions/45953/php-execute-a-background-process for information. – Nigel Ren May 05 '21 at 18:14
  • @NIgel Ren thank you Nigel, as I said I am on a shared hosting server, so exec, kill and similar commands are disabled. – fede72bari May 05 '21 at 18:36

0 Answers0