1

I have a PHP script on my website that downloads a huge file (10-15 Mb), processes it, and updates a database. This script should be run once every day to make sure that the database is updated to the latest version.

I wonder if I can spawn/intiate a background process when the first user visits the website... conceptual as showed below:

<?php
    require_once("my_data_downloader_and_updater.php");

    if (is_first_visit_today) {
        // This function call will probably take a couple of minutes... and I don't want the user to notice the delay
        download_and_update_data();  
    }

    echo "Welcome to this website";
?>

Can I run download_and_update_data as a separate process or parallel running function without delaying the response to the user? Or should I use any other techniques (e.g. schedule daily "ping events" to the website, that intiates the function above)

Gowire
  • 1,046
  • 6
  • 27
  • 1
    Why don't you use CRON JOB or Scheduler for this task? – Sachin Sep 18 '20 at 09:42
  • There are quite a lot of ways to approach this - job queues, schedulers, daemons, process forking, etc - so I don't think this can be answered succinctly in this format. – IMSoP Sep 18 '20 at 09:48
  • 1
    PS "10-15 Mb" isn't generally considered "huge" these days; unless it was a typo for Gb, that's the average size of a raw digital camera image, and it's not uncommon for an Excel spreadsheet to grow to that size in normal use. – IMSoP Sep 18 '20 at 09:51

0 Answers0