search

Home  >  Q&A  >  body text

Simulate Cron jobs using PHP

<p>I am running an LMS (Learning Management System) online and it needs to run a file called "training/admin/cli/cron.php" every minute. The problem is that my host only allows cron jobs to run every 30 minutes. </p> <p>I tried creating a file called cron_script.php with the following content and setting it to run every 30 minutes: </p> <pre class="brush:php;toolbar:false;"><?php set_time_limit(0); $turns=0; while($turns < 30) { exec('training/admin/cli/cron.php'); sleep(60); $turns ; } ?></pre> <p>But it only seems to run once. I don't even know how to fix the error message since it is run by cron so I can't print it anywhere. </p>
P粉207483087P粉207483087452 days ago520

reply all(1)I'll reply

  • P粉475315142

    P粉4753151422023-09-05 10:37:32

    this is possible. Because the default run time limit is 30 seconds. Use this function https://www.php.net/manual/en/ function.set-time-limit.php Or modify the "max_execution_time" value of the php.ini file.

    reply
    0
  • Cancelreply