Announcement

Collapse
No announcement yet.

Use PHP to create a one time cron job

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use PHP to create a one time cron job

    Wanted to get some ideas on what the best way to use PHP to create a one time cron job.

    Here is the scenario I’m looking at:

    Someone does a "transaction" on the website and at the same time as this transaction script, the script would also create a cron job. The cron job would run 10 mins from the time the transaction script is run. The cron job would simply call a PHP script.
    Last edited by Justec; 05-09-2005, 02:56 PM.
    [ JUSTIN ]
    [ OFF unit ]
    [ WEB DESIGN / DEVELOPMENT, GRAPHIC DESIGN, OTHER STUFF
    ]

  • #2
    It's probably easier/safer to just have a standing cron job to run every so often that checks timestamps on this transaction to gauge when 10 minutes has passed Justin. Creating cron jobs with PHP scripts would require some user and/or permissions massaging that doesn't really add anything except for security issues.

    Chris
    Chris Wells
    InterWorx L.L.C. | http://interworx.com
    InterWorx Control Panel

    Comment


    • #3
      Originally posted by IWorx-Chris
      It's probably easier/safer to just have a standing cron job to run every so often that checks timestamps on this transaction to gauge when 10 minutes has passed Justin. Creating cron jobs with PHP scripts would require some user and/or permissions massaging that doesn't really add anything except for security issues.

      Chris
      Thanks for the advice Chris. My original thought was to just have a cron job run every 10 mins. Basically I have a site that faxes orders and then using web services you can check the status of the fax. I was thinking that doing the cron job every 10 mins would not be the most efficient way of doing it. Since this is my site managed on my server I was thinking I could somehow give permission for just one user, but if it could cause problems with other sites it may not be worth it like you said.

      Now that I think about it the cron’d web service PHP script isn’t that intensive. I would just check my order database for orders in the last 10 mins and then connect to the web service server and send then the data and wait for the response. Not much more than someone visiting the website every 10 mins.

      So based on the fact that this is my own site would you still recommend doing it with a script every 10 mins instead of the “on demand” script?

      The only other thing I can think of is to have a PHP script call another PHP file with a long wait as the first line. So it would just sleep for 10 mins before running.

      Thanks for the non-iworx suggestions, I appreciate it.
      [ JUSTIN ]
      [ OFF unit ]
      [ WEB DESIGN / DEVELOPMENT, GRAPHIC DESIGN, OTHER STUFF
      ]

      Comment


      • #4
        I'd say a standing cron job is a good solution. The overhead would be minimal and security-wise you'll be better off as well. It is probably much easier to debug too, since the interval is regular :).


        Chris
        Chris Wells
        InterWorx L.L.C. | http://interworx.com
        InterWorx Control Panel

        Comment


        • #5
          I agree with Chris. I have a production server that performs such action.

          Say you need to add a line to a big file, instead of generating the entire big file each time. You set a cronjob that looks if any new line needs to be added and performs the operation -looking on a stack-file or something, that you fill on every transaction- .

          If the PHP script being called by the cronjob exits nicely the most part of the time -no new lines have to be added-, there is no overhead at all.

          Regards,

          Juan
          www.sowsl.com

          Comment

          Working...
          X