SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast jagat_21's Avatar
    Join Date
    Jun 2007
    Location
    Ahmedabad,India
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb How To Execute Cron Job Manually ?

    Hi All,

    Currently We have scheduled No. Of Cron Jobs which will be executed As per the schedule time.

    Using PHP Can We execute the cron job Manually ?

    As per my experience, we can directly execute the PHP Script that we have setup in the cron job.

    But is it possible to execute the cron job manully using the linux command that we can pass to php's exec() function ?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    execute the cron job manully using the linux command that we can pass to php's exec() function ?
    It sounds like you already have your solution.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Enthusiast jagat_21's Avatar
    Join Date
    Jun 2007
    Location
    Ahmedabad,India
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But i want to know, how can we call cron job command using php's exec() function ?

    Each cron job will take more than 15 hours to complete the process. So If i will allow the user to run cron job script through a external url there will be problem related to connection and all.

    If the script is terminated then the execution for rest of the process will not be completed.

    I have no. of stored procedures that will be called one after another in the php script. So let us assume that if currently user has started cron job and one stored procedure execution is in process at that time if the connection is lost then rest of the stored procedures mentioned in the php script will not be called.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Why not create a table in a RDBMS of your choosing to store completed / pending runs?

    You could create a PHP script to create a pending entry in this table, then increase your current CRON frequency to check this table and decide whether or not to run.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Enthusiast jagat_21's Avatar
    Join Date
    Jun 2007
    Location
    Ahmedabad,India
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, i have already implemented that thing. And i am tracking the scheduled cronjob status in that way. But the thing is that now we have user who will be executing the script.

    For example, if user has started the cron job script manually from external URL. And after some time if user closes the browser intentionally or unintentionally or system is switched off or anything from client side then the execution of rest of the script will be stopped.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The script the user is calling, should NOT be the script that process your job. It should only create an entry in your job table as pending.

    It would essentially only consist of the following:-
    PHP Code:
    <?php
    /**
     * ==Statuses==
     * 
     * 0 = Requested / Pending
     * 1 = Running
     * 2 = Complete
     * 3 = Cancelled
     */
    #UserRunRequest.php
    $sSQL sprtinf("INSERT INTO table (user, requested, completed, status)VALUES('%s', %s, 0, 0);",
        
    $sUsername,
        
    time()
    );
    $rResult mysql_query($sSQL);
    ?>
    You would then have a separate script that would determine how to proceed based on the data contained within the queue.

    • Has a job ran in the x hours, if so cancel all current requests
    • If no jobs scheduled and its been over x hours schedule a job and run it marking its status as 'running'.
    • etc...
    • etc..
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    execute the php binary from a shell
    Code:
    /usr/bin/php /path/to/script.php > /dev/null &

  8. #8
    SitePoint Enthusiast jagat_21's Avatar
    Join Date
    Jun 2007
    Location
    Ahmedabad,India
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    execute the php binary from a shell
    Code:
    /usr/bin/php /path/to/script.php > /dev/null &

    Can I call the above mentioned command using php's exec() function ?


    Because the cron script will be executed by the user. And after calling the script if user closes the browser than also i want the procees to be continued.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •