0

This is the scenario:

  • User clicks on Login
  • Login.php runs (after it is done, redirect using header() )
  • updater.php needs to run in background after Login.php
  • User can use website after Login.php

updater.php takes about 5 minutes to finish running which is why it is separated from the login.php, which is also why it needs to run in the background after login.php in the meanwhile the user is free to use most parts of the website (the remainder after updater.php is done). I can't use include() as this will stall the login.php and won't redirect the user back until updater.php is finished.. I read about using Header() before include but it seems like sometimes, it does not run the full updater.php script (sometimes just 40% or 50% before it stops).

I guess I can use CURL to activate the script without affecting the loading time of login.php?

What is the best way to handle this? Please let me know if anything doesn't make sense.

Thank you.

  • Why does `updater.php` need to run after `login.php`? Why can't `login.php` just include the same functionality, or alternatively use `include()`? Also, a script should not take 5 minutes to run. That's probably a bigger concern than getting one script to run after the other. As for actual application, you could use either AJAX or cron jobs. – Obsidian Age Mar 02 '18 at 01:01
  • @ObsidianAge For the sake of simplicity imagine login is just a simple select * db where user = 'account' and pass='internal' & create session if credentials are matched. After this login is done, updater uses an api to retrieve ALOT of account data from another service and upserts it in the account information table. Using a webhook would be ideal, but that other service isn't mine! For now imagine you have this scenario, and changing updater.php is not the solution. –  Mar 02 '18 at 01:13
  • @jerome Is there an advantage to using AJAX over CURL? –  Mar 02 '18 at 01:14
  • ajax is absolutely not the solution, see the answer below – Wreigh Mar 02 '18 at 01:14

1 Answers1

1

if you don't mind executing results, you can use
exec("nohup php ./update.php >>/path/to/save/log 2>>/path/to/error_log &").

winlans
  • 91
  • 5
  • Forgive my ignorance, what do you mean by executing results? –  Mar 02 '18 at 01:15
  • It seems that your question has been well explained.[look is](https://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php) – winlans Mar 02 '18 at 01:29
  • Hi, this doesn't seem to be working for me. `exec("Functions/update.php >/dev/null &");` I have opened it on a browser and it works fine. What could be the problem? –  Mar 03 '18 at 18:26