SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    running a cron every 60 seconds

    Hi guys

    for testing purposes i want to run my cron every 60 seconds
    what is the code to run it every 60 seconds

    PHP Code:
    //delete entries over 60 seconds old
     
    @mysql_query('DELETE * FROM jobs WHERE startdate<'.(time()-60)); 

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, the timing is determined by your crontab. There is nothing you do in PHP to define how often the script runs. How you do this will depend on your hosting control panel, or if you are interacting with the crontab directly.

    Your query also has an error. Remove the *
    i.e the query should just be DELETE FROM jobs ....

    You should also remove the @ so any errors can be logged and you can see what they were.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Frankfurt/Germany
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I am confused. Cron has nothing to do with your mysql query.

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my code. does it look right?

    As nothing seems to work or appear, when i access the file


    PHP Code:
    <?php



    //connect to your database ** EDIT REQUIRED HERE ** 

    mysql_connect("localhost","notexper_two","three"); //(host, username, password) 



    //specify database ** EDIT REQUIRED HERE ** 

    mysql_select_db("notexper_one") or die("Unable to select database"); //select which database we're using 




    //delete entries over 60 seconds old



    $query = ("DELETE FROM jobs where startdate<'.(time()-60)"); 
                  

    $result mysql_query($query)or die(mysql_error()); 





    ?>

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, you're trying to call the time function in the middle of a string. It's just gonna send that text directly to MySQL.

    Try this (brackets are also incorrect)
    PHP Code:
    $query 'DELETE FROM jobs WHERE startdate < ' time()-60

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Btw, turn on error reporting (display errors on your local server) so you can get some info about problems. Search the PHP manual for how to modify the php.ini file to do this.

  7. #7
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my error after changing it

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '-60' at line 1

  8. #8
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then you have to echo $query to see what is being sent to mysql.

  9. #9
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    -60 is what was returned

  10. #10
    SitePoint Addict The Mog's Avatar
    Join Date
    Dec 2002
    Location
    Manchester UK
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add this under your query, to see what the php is trying to do..

    print 'DELETE FROM jobs WHERE startdate < ' . time()-60;

  11. #11
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad. try this:
    PHP Code:
    $query 'DELETE FROM jobs WHERE startdate < ' . (time()-60); 
    That will produce a query that looks something like this:
    Code SQL:
    DELETE FROM jobs WHERE startdate < 1181305523


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
  •