0

Is it possible to run a PHP script in the background while the user is navigating from one page to another?

If yes, how to run a PHP function in the background after a user login and display the output of the function under certain area of the page on which he/she clicked?

Thanks.

akhil regonda
  • 159
  • 2
  • 13

1 Answers1

1

You need to create a worker. There are various ways of doing this. Look at Gearman.org or look at RabbitMQ or another message queue system like it.

With these you can create a non-blocking PHP background worker that is triggered by your main script.

You can also potentially build your own: https://secure.php.net/manual/en/class.worker.php

Links for tutorial:

https://www.rabbitmq.com/tutorials/tutorial-two-php.html

There are quite some guides how to create Deamons with PHP: http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/

Or how to background a process:

http://waynepan.com/2007/10/11/how-to-use-ignore_user_abort-to-do-process-out-of-band/

Renati
  • 56
  • 8
geoidesic
  • 4,649
  • 3
  • 39
  • 59
  • you can just use exec etc, no need to get fancy :-), and link only answers are discouraged –  Feb 19 '18 at 20:09