You need to run the php script in the background through the finished shell.

The scheme is as follows: form-> data transfer-> worker

All this is necessary because after 60 seconds the script will die at the browser, but inside it will not be. Script parsit a bunch of data and at the same time processes, generates. PS - crown does not fit

  • one
    What exactly has caused you trouble? what were you trying to do? Please specify the full question: ru.stackoverflow.com/help/asking - aleksandr barakin
  • Run through the form of the script in the background as after 60 seconds the script will die when the browser is inside, but this will not happen inside. Script parsit a bunch of data. - Mikhail Khalupov
  • Please add the question text by clicking edit . - aleksandr barakin

2 answers 2

because after 60 seconds the script will die when the browser is open, but inside it will not be

Php has a setting in the settings responsible for the timeout. Specify more than 60 seconds in the script. and you will be happy ( documentation ):

set_time_limit(0); 

You can also increase the RAM limit ( documentation ):

 ini_set('memory_limit', '1G'); 

Or option via web sockets. You can even make a progress bar. This will help pcntl-fork with ReactPhp . Run php as a daemon (for example through a screen or supervisior ), proxy through Nginx and enjoy life. The only thing you need to write your PPM to use all the cores. PPM article

Addition

After discussions:

  1. Make a request from the client (browser)
  2. In this script, run another script (for example through pcntl_fork or exec ("php ...") )
  3. Give the answer to the client about the launch of a long script
  4. With repeated requests, you can check the status of a long script.
  • Hmmm, the browser keep 20-30 minutes. Not really. Yes, and hosting will not allow. Further to assemble PCP with a fork is also not possible, and no desire. I read somewhere on the Internet through the system () command; background to do - Mikhail Khalupov
  • @ Mikhail Khalupov what is your task? It may be enough to save the record of the necessary work in the database, and after cron, check every minute and run a php script without a timeout? - korytoff pm
  • Not bad. In general, I ask you to consider an even simpler option. - system ("php -f script.php> / dev / null 2> & 1 &"); - Mikhail Khalupov
  • @ Mikhail Khalupov, yes, updated the answer - korytoff

Constantly working worker than not suitable? Let it hang itself, it works, it waits for tasks from a new record in the database, a file appeared in the folder, or it will be listened to by the gearman .

As soon as a task appears, it processes it and waits further.

Of the shortcomings - eating memory, even when waiting, can swell. Option to periodically restart it.

  • According tasks appropriate. But not very convenient. Therefore, as long as an option - Mikhail Khalupov
  • "Not very convenient" - where is it too tight? - Sergiks pm
  • It is more convenient when pressed, processed, killed. And keep the worker on forever and it’s not cool to restart yet. - Mikhail Khalupov
  • @ Mikhail Khalupov you are probably confusing concepts. When I clicked, processed and killed, then this is not a worker, but php in its most usual form - korytoff
  • @korytoff I did not put it right. I clicked, transferred data, the browser closed, a script worked for a couple of hours in the background and was killed at the end - Mikhail Khalupov