SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    PHP Listener to delay actions

    Good day all,

    I am a pretty new puppy to PHP, although I have a reasonable amount of knowledge to help myself around the platform.

    I ran into a problem a few days ago, and I had absolutely no idea what needs to be done. Maybe there is someone clever enough to help me with this situation.

    Here goes...
    Let's say that I have a form which captures a name, email, etc. This data then gets stored in a table with corresponding fields. I want a small script which will check the values of a field every hour and then use an if statement to execute an action. This will be mainly used for emailing users.

    In other words...if a user orders the product, there will be a field with the name 'order' and its value will be 'yes' / 'true' for that user. If a user has not yet ordered the prodcuct, the default value will still be there which is 'no' / 'false'. The script will email all users with the value 'no' / 'false'.

    I was thinking that this can be done with Cronjobs if one has Curl installed on your server. I really don't know how to do this. (what command do I use?)

    Thank You.
    I hope that someone can assist me with this.

    Best Regards,
    Contrid

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you looking for help with the PHP or help with the cron job?

    Here's a rough sketch of how the PHP would look:

    PHP Code:
    mysql_connect( ); // put in your connect settings
    mysql_select_db(); // select your database

    mysql_query'SELECT users from table where ordered = 0' // replace with correct sql query

    while( $row mysql_fetch_array() )
    {
        
    $message 'Please order this'// replace this with what you want to say
        
    $subject 'Order now!'// same

        
    mail$row['email_address'], $subject$message$headers // see http://us2.php.net/manual/en/function.mail.php for details on $headers and such
    }


  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    UFTimmy,

    Thank you for the reply. Yeah...I don't really need the php code, for I can do that. I just need to learn how to do the Cronjob. I haven't done anything like this before, and I have no idea what command to use.

    Can you still help me with this?

    Thank You very much.

  4. #4
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sadly, I can't. The host I've used has a cron job section of the Cpanel where I just typed in the name of the script and the time I wanted it run.

    Are you doing your own hosting, or are you paying a host? If you're paying a host, check with them on how to do it.

  5. #5
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would do something like this:

    Code:
    php /path/to/script.php
    It's about as simple as that. Well, plus the other parts of the cron.

  6. #6
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by devbanana
    You would do something like this:

    Code:
    php /path/to/script.php
    It's about as simple as that. Well, plus the other parts of the cron.
    Thank you very much.
    Is it really as easy as just pointing to the file or method?
    I thought it was going to be much more complicated. I will try it, and let you know right here on this thread.

    Yes, I have a shared server and there is a Cronjobs section in cPanel. I just didn't know what command to put in there. I have the PHP script ready, so that isn't a problem.

    Thanks again guys for your help.

  7. #7
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Contrid
    Thank you very much.
    Is it really as easy as just pointing to the file or method?
    I thought it was going to be much more complicated. I will try it, and let you know right here on this thread.

    Yes, I have a shared server and there is a Cronjobs section in cPanel. I just didn't know what command to put in there. I have the PHP script ready, so that isn't a problem.

    Thanks again guys for your help.
    Yes, it is really that simple.

    In the script itself, if you put:
    Code:
    #!/usr/bin/php
    on the first line, even before the opening PHP tag, then chmod the script to 755, then you can just enter:
    Code:
    /path/to/script.php
    and it'll know to execute php automatically.


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
  •