2 Replies Latest reply on Sep 27, 2011 5:23 PM by FlyingGuy

    Executing another php file


      I am new to php programming
      As part of one activity I new to schedule below three php files from cronjob at 10,11,12PM respectively

      0 10 * * * php -q /home/produsr/newtask22/gather.php
      0 11 * * * php -q /home/produsr/newtask22/upload.php
      0 12 * * * php -q /home/produsr/newtask22/report.php
      Now due to some issue by scheduling 3 cron jobs, I need to run above three php files from one php like

      #start newtask22
      execute php -q /home/produsr/newtask22/gather.php
      sleep 1hour #
      execute php -q /home/produsr/newtask22/upload.php
      sleep 1hour
      execute php -q /home/produsr/newtask22/report.php
      #end newtask22
      Please let me know how to do so in php

      I tried and wrote below script but not sure whether its right or not
          exec("php -q /home/produsr/newtask22/gather.php");
          exec("php -q /home/produsr/newtask22/upload.php");
          exec("php -q /home/produsr/newtask22/report.php");
      Please correct my code :)
        • 1. Re: Executing another php file
          You could naively do:
          However you might want to review & refactor the code since it will be "long running" and might hold onto resources unnecessarily.
          • 2. Re: Executing another php file
            Running php from the cron scheduler works as you know but there are ways to do this better and still use cron.

            Wrap your jobs into a shell script. This way you can get the PID of the running job and then test to see if each job is finished prior to launching the next one.

            Just a thought