Professional Web Applications Themes

Timed event while looping - PHP Development

I've got a php command line script (on Windows XP) that copies files from one directory to another every 2 minutes. To make it loop I'm basically using: while (0) { processes; sleep (120); } The script also writes everything it does to a log every 2 minutes as well. Because the log file becomes somewhat large after a day, I'd like to rotate it at or around midnight every day. My first thought was to simply check against epoch through each loop, and if epoch is greater than 86400 seconds (24 hrs) then rotate. This would work ok for ...

  1. #1

    Default Timed event while looping

    I've got a php command line script (on Windows XP) that copies files from
    one directory to another every 2 minutes. To make it loop I'm basically
    using:

    while (0) {

    processes;
    sleep (120);

    }

    The script also writes everything it does to a log every 2 minutes as well.
    Because the log file becomes somewhat large after a day, I'd like to rotate
    it at or around midnight every day. My first thought was to simply check
    against epoch through each loop, and if epoch is greater than 86400 seconds
    (24 hrs) then rotate. This would work ok for this 2 minute loop, but may not
    work too well if the loop was more like an hour.

    Is there a better way to do this?

    I've thought about doing the loop in a different way that would make this
    more accurate, but I'm concerned about the increased resources this might
    take.

    The idea is to not use sleep (or sleep every minute), and on each loop to
    check the time. If two minutes, or whatever interval has passed, run the
    processes. This method would make any kind of timed event at a certain
    hour/minute more accurate, but I'm not sure if it is more resource intensive
    than sleep.

    Thanks for any help...

    Max


    Max Guest

  2. #2

    Default Re: Timed event while looping

    With sleep in your loop, the program will wait for 120 seconds. If you
    run the loop continuously and check the time on each iteration, the
    loop would be running continuously. Without actually trying both
    methods, I think the sleep() inside the loop is probably the better
    solution because it avoids the constant "spinning" of the while loop.

    As far as the log file is concerned, why not just check the current
    date inside the loop and write to an appropriate log file? Something
    like:

    while (0) {
    $logFile = '/path/to/log/' . date('Ymd') . '.log';
    processes;
    sleep (120);
    }

    This will get you one log file per day, regardless of how long the
    interval is or when you start the loop.

    ZeldorBlat Guest

  3. #3

    Default Re: Timed event while looping

    Thanks for the idea. A simple yet effective solution I had not thought of.

    Max

    "ZeldorBlat" <com> wrote in message
    news:googlegroups.com... 


    Max Guest

  4. #4

    Default Re: Timed event while looping

    Unix-like systems have a utility called "cron" that manages timed tasks
    throughout the system. I am not sure if Windows has this by default, but
    you can probably find one
    ( http://www.google.com/search?q=cron+for+windows ). You might want to
    look into this, as it is a much more mature system than a quick PHP script
    could allow.

    Peace,
    Ryan

    Max wrote:
     

    --
    Peace,
    Ryan 'RetroMan' Heuser
    Ryan Guest

  5. #5

    Default Re: Timed event while looping

    I'm familar with Cron and use in on linux systems quite regularly. Windows
    also has 'Scheduled Tasks'. However, when deploying a package that someone
    else will be configuring, I think you are much better off with self
    contained timing mechanisms.

    Thanks,
    Max


    "Ryan Heuser" <com> wrote in message
    news:ddpc88$uqg$nerdc.ufl.edu... 
    >
    > --
    > Peace,
    > Ryan 'RetroMan' Heuser[/ref]


    Max Guest

Similar Threads

  1. Launching HTTPService with timed event
    By Developer504 in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 2nd, 03:29 AM
  2. basic looping help (want to stop looping in layer)
    By hamish@sullivanparkmedia.com in forum Macromedia Flash
    Replies: 2
    Last Post: February 22nd, 05:34 AM
  3. Getting Error: Event Type 'flash.event:event' is unavailable ?????
    By malik.robinson@gmail.com in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: January 14th, 01:51 AM
  4. RPC: Timed out
    By Alan in forum FreeBSD
    Replies: 3
    Last Post: March 29th, 08:07 PM
  5. The Operation has timed-out
    By Romano Live in forum ASP.NET
    Replies: 0
    Last Post: October 27th, 01:14 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139