Delayed code execution in php

0 like 0 dislike
5 views
Welcome!

Faced such question — how to implement the following:

The user comes to the page a.php, it redirects to b.php and at the same time, calls and executes the c.php
C.php a resource — intensive script that I would like to run in the background while the user continue going about their business on b.php
by | 5 views

7 Answers

0 like 0 dislike
You can:
exec("/usr/bin/php /var/www/c.php > /dev/null &");
Then exec will release the console and the script b.php will run on and c.php will work in the background.
by
0 like 0 dislike
ZendX_Console_Process_Unix. Really only works on *nikah and requires a php extension shmop, posix and pcntl. But it is easy to use as boots.
by
0 like 0 dislike
In b.php on the server side, send a POST request (using sockets) c.php and close the connection without waiting for a response. But for this c.php you will need to enable ignore_user_abort.
by
0 like 0 dislike
the user went to the page and start Ajax post request, I think the most simple and logical solution.
by
0 like 0 dislike
c.php loaded Ajax or in an iframe.
\r
in the script settimelimit(0) to remove time limit
\r
if the task can be split "portion" that is good. while small portions of the same Ajax, then you can even show the loading indicator.
by
0 like 0 dislike
Went to a.php created file task.txt with the line settings (if necessary)
Then for the crown we have runs every minite PHP script checker, file task.txt which executes the desired command
exec("/usr/bin/php /var/www/c.php > /dev/null ");
by
0 like 0 dislike
View Gearman ( gearman.org/ ). It just for such a purpose is suitable and there is integration with php. Review article — highload.com.ua/index.php/2010/07/09/gearman-и-php-асинхронные-задачи/
by

Related questions

0 like 0 dislike
2 answers
asked Apr 25, 2019 by Paul_Morte
0 like 0 dislike
1 answer
asked Jun 13, 2019 by VegasChickiChicki
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked May 21, 2019 by rabodis
110,608 questions
257,186 answers
0 comments
28,888 users