Using PHP for nightly backend tasks?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles

    #1

    Using PHP for nightly backend tasks?

    I have to develop a script to be run nightly to go through a database
    and send emails based on conditions. It's a large database, and there
    are several thousands of emails to be sent during the week everyday.
    The script will be run with a cron job at midnight or so.

    I was wondering if PHP is suitable for this, or may it be problematic,
    for instance would its execution abort after a certain amount of time?
    Or is it perfectly fine for this task?
    Thanks.

  • Gordon Burditt

    #2
    Re: Using PHP for nightly backend tasks?

    >I have to develop a script to be run nightly to go through a database
    >and send emails based on conditions. It's a large database, and there
    >are several thousands of emails to be sent during the week everyday.
    >The script will be run with a cron job at midnight or so.
    >
    >I was wondering if PHP is suitable for this, or may it be problematic,
    >for instance would its execution abort after a certain amount of time?
    >Or is it perfectly fine for this task?
    You may want command-line PHP for this task. The interface is a
    little different (e.g. no $_GET and $_POST) but you can set different
    parameters and I believe the run time limit defaults to infinite.
    Anyway, the parameters can be put in a different .ini file and set
    differently than for web-based PHP.

    Comment

    • C.

      #3
      Re: Using PHP for nightly backend tasks?

      On 18 Jul, 00:09, gordonb.h6...@b urditt.org (Gordon Burditt) wrote:
      I have to develop a script to be run nightly to go through a database
      and send emails based on conditions. It's a large database, and there
      are several thousands of emails to be sent during the week everyday.
      The script will be run with a cron job at midnight or so.
      >
      I was wondering if PHP is suitable for this, or may it be problematic,
      for instance would its execution abort after a certain amount of time?
      Or is it perfectly fine for this task?
      >
      You may want command-line PHP for this task. The interface is a
      little different (e.g. no $_GET and $_POST) but you can set different
      parameters and I believe the run time limit defaults to infinite.
      Anyway, the parameters can be put in a different .ini file and set
      differently than for web-based PHP.

      You can set the time limit at run time. Also, while using the CLI PHP
      (which cames as standard with the SAPI module in most Linux distros)
      is the prefered option, you can invoke a web page using the wget
      command (or curl) - but, in addition to to getting your webserver to
      maintain a very long connection, you would need to expose the relevant
      script via the web interface.

      To run the php script from the command line...

      php -q /some/where/mysrcipt.php

      or insert the path to the command processor as the first line of your
      script and make it executable:

      #!/usr/bin/php5
      <php>
      .....

      chmod ug+x /some/where/mysrcipt.php

      C.



      Comment

      • MonTassaR

        #4
        Re: Using PHP for nightly backend tasks?

        On Jul 18, 1:09 am, gordonb.h6...@b urditt.org (Gordon Burditt) wrote:
        I have to develop a script to be run nightly to go through a database
        and send emails based on conditions. It's a large database, and there
        are several thousands of emails to be sent during the week everyday.
        The script will be run with a cron job at midnight or so.
        >
        I was wondering if PHP is suitable for this, or may it be problematic,
        for instance would its execution abort after a certain amount of time?
        Or is it perfectly fine for this task?
        >
        You may want command-line PHP for this task. The interface is a
        little different (e.g. no $_GET and $_POST) but you can set different
        parameters and I believe the run time limit defaults to infinite.
        Anyway, the parameters can be put in a different .ini file and set
        differently than for web-based PHP.

        I'd rather use set_time_limit( ) if php is not running in safe mode.
        I just want to mention that if you plan to send a personalised content
        for each contat, you may want to use an temporary table where, at the
        begining of the mailing process you want to implement, you prepare
        your data (associate mail adress and other contact stuff with suitable
        content) using php, then launch an other script tha just grab data
        from this temporary table and send it, this will considerably minimise
        exectime and load on your server ..
        Adding a sent/not_sent flag to this temp table would let you resume
        sending mails if some things goes wrong with your smtp for example ..

        Comment

        • NC

          #5
          Re: Using PHP for nightly backend tasks?

          On Jul 17, 3:04 pm, Charles <landema...@gma il.comwrote:
          >
          I have to develop a script to be run nightly to go through
          a database and send emails based on conditions. It's a large
          database, and there are several thousands of emails to be
          sent during the week everyday. The script will be run with
          a cron job at midnight or so.
          >
          I was wondering if PHP is suitable for this
          Absolutely, as long as you have a command-line interpreter on your
          system. With PHP is executed from the command line, timeouts do not
          apply; the script behaves as any other shell script would.

          Cheers,
          NC

          Comment

          Working...