Running php scripts with cron jobs at random different times each day??????

Discussion in 'PHP' started by ricky001, Feb 17, 2011.

  1. #1
    Hi friends,

    I have 10 scripts written in php. and I want to execute these scripts at different random times each day.
    I have created cron jobs to run these. But these can execute only on a specific set time-period, which I don't want.
    I want that these cron jobs execute at different random times like in any random order.
    It can like this.....
    5,2,8,6,4,9,3....
    8,3,5,2,1,7,4,6,....
    and so on....

    How can I do this? Please help me.......
     
    ricky001, Feb 17, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Schedule a cron job to run at preset intervals throughout the day and have it run a master PHP script that randomly chooses to run one of the desired scripts, or no script at all.
     
    rainborick, Feb 17, 2011 IP
  3. ricky001

    ricky001 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot Rainborick for your reply.
    But As I am a newbie in the php world, I don't know much about coding. Can you please give me an example of the master php script, that will execute the scripts randomly.....
     
    ricky001, Feb 17, 2011 IP
  4. Scoty

    Scoty Active Member

    Messages:
    620
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I'm not great with PHP either, but to do that I would put in he random function to pick a number up to and including 10 if it returns 0 then do nothing, otherwise when it returns 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 then run the corresponding script. I would then use the include function to pull in whatever the script is, but again, I'm not great at this
    like:

    $num = rand(10);
    if ($num == 0) { //do nothing }
    else if ($num == 1) { include 'script1.php'; } else if..etc.

    Of course you don't need to keep putting else, that's just the way I do it
     
    Last edited: Feb 18, 2011
    Scoty, Feb 18, 2011 IP
  5. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #5
    
    <?php
        $num = rand(10);
        if(file_exists('script'.$num.'.php'))
            include('script'.$num.'.php');
    ?>
    
    PHP:
     
    tvoodoo, Feb 18, 2011 IP
  6. aRo`

    aRo` Peon

    Messages:
    141
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    an other way would be to overwrite your ini file each run
     
    aRo`, Feb 19, 2011 IP