0

I have a code called "script.php" , it checks on my users and re-news their orders. However I want to create a button so that whenever I click the button; which is linked to "script.php" it will run. I created a button that does that:

<?php echo Html::anchor('../../script.php', 'Run Renewal Cron', array('class' => 'btn btn-success')); ?>

It works but the browser takes forever, since the script is running through many users. Is there a way that when I click this button, the script runs inside the server itself so if the browser was to close the script will keep running?

The code is just queries, selecting users, updating them, also adding new records to those users.

john
  • 157
  • 2
  • 12
  • There are many possible answer. For example `script.php` could enqueue a task and return immediately. But as it is, your question is way too broad. – Federico klez Culloca Sep 21 '17 at 12:35
  • Are you using some framework? If the task is long running, you should use Queues/Jobs (Laravel features it) to run it. – Elias Soares Sep 21 '17 at 12:35
  • Are you asking about [Crons](https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php), possibly? – Script47 Sep 21 '17 at 12:35
  • How is about creating a cron job ? see here : https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php – Istiaque Ahmed Sep 21 '17 at 12:37
  • 1
    Why everyone posting about cron when it's not what he explained – rak007 Sep 21 '17 at 12:43
  • No the script is just a query to get the users and do a few updates and add more records. Im not using any type of frame work, I just need it to run even if anything interrupts it. @EliasSoares – john Sep 21 '17 at 12:45
  • You should add more code to your question, so we can help you further. At this point we're just guessing. – Classified Sep 21 '17 at 12:46
  • I updated my questions @Classified – john Sep 21 '17 at 13:03
  • Your `'../../script.php'` should probably only worry about the logged in user, instead of everyone. If you do need something that need to run for everyone, set it as a cron job. – user176717 Sep 22 '17 at 18:22

1 Answers1

-2

If you have control over your server, you can do this :

set_time_limit(0);
ignore_user_abort(1);
rak007
  • 973
  • 12
  • 26
  • He is asking for a way to let his script running even when he closes his browser, this is a straightforward answer to his question – rak007 Sep 21 '17 at 12:40
  • @john Yes try to add this to your script page, on the first lines. If your php ini config accepts this, you'll be all good – rak007 Sep 21 '17 at 13:07