Jump to content

PHP Cron not working properly


Exoon

Recommended Posts

Hello,

 

Ive got two databases, one is called db_que which all my videos get added too, i want it so every 6 hours a video from the db_que gets moved to db.

 

I setup this script and it works fine when i run it manually but when i setup a cron all of the videos getting adding in 1 go, i only want it to move 1 video every 6 hours.

 

I setup the cron in Directadmin. Heres the values i put:

 

Minutes: *

Hours */6

Day of month: *

Month *

day of week *

command : /usr/local/bin/php /home/username/public_html/admin/add_qued.php

 

<?php
include("connect.php");

$sql_vid = "SELECT * FROM db_que ORDER by vid_id ASC limit 1";
$result_vid = mysql_query($sql_vid) or die(mysql_error());
$count_rows = mysql_num_rows($result_vid);

if ($count_rows != 0) {

$row_vid = mysql_fetch_assoc($result_vid);


$vid_id = $row_vid['vid_id'];
$vid_url = $row_vid['vid_url'];
$vid_cat = $row_vid['vid_cat'];
$vid_title = $row_vid['vid_title'];
$vid_screen = $row_vid['vid_screen'];
$vid_tag1 = $row_vid['vid_tag1'];
$vid_tag2 = $row_vid['vid_tag2'];
$vid_tag3 = $row_vid['vid_tag3'];
$vid_tag4 = $row_vid['vid_tag4'];
$vid_tag5 = $row_vid['vid_tag5'];
$vid_tag6 = $row_vid['vid_tag6'];
$vid_tag7 = $row_vid['vid_tag7'];
$vid_tag8 = $row_vid['vid_tag8'];
$vid_cat = $row_vid['vid_cat'];
$vid_length = $row_vid['vid_length'];
$vid_mainpage = $row_vid['vid_mainpage'];
$vid_time = date("G:i:s");


    $sql = "INSERT INTO db(vid_title, vid_tag1, vid_tag2, vid_tag3, vid_tag4, vid_tag5, vid_tag6, vid_tag7, vid_tag8,
     vid_cat, vid_url, vid_screen, vid_date, vid_length, vid_mainpage, time) 
    VALUES('" .$vid_title. "', '" .$vid_tag1. "', '" .$vid_tag2. "', '" .$vid_tag3. "',
     '" .$vid_tag4. "', '" .$vid_tag5. "', '" .$vid_tag6. "', '" .$vid_tag7. "', '" .$vid_tag8. "', '" .$vid_cat. "', '" .$vid_url. "', '" .$vid_screen. "', '" .$vid_date. "', '" .$vid_length. "', '" .$vid_mainpage. "', '" .$vid_time. "')";

if ($result = mysql_query($sql)) {
    echo "adding".$vid_id;
    $sql_del = "DELETE FROM `db_que` WHERE vid_id = '$vid_id'";
    echo "<br><br>Move Successfull<br><br>now, deleting from the qued database".$vid_id;
    mysql_query($sql_del);
  } else {
    echo "error";
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/146723-php-cron-not-working-properly/
Share on other sites

I cannot remember but I think the hours should be 0/6  not */6.

 

You may want to read up more on Cron Syntax as this is a result of the cron running too often, I believe.

 

As for the script, I would change $count_rows != 0 to == 1 that way you know if more rows are being returned (for whatever reason) that will not run. I would also have it log to an "Error" file if that is the case so you can see what is happening on an error.

Hello, i just tried running this using */6 in the minutes section and it runs every 6 minutes fine, just moving over 1 video every 6 minutes.

 

 

i was reading a cron tutorial and it said this:

 

The */5 is known as a short form equivalent to 0,5,10,15,20 etc... and achieves the same effect as the previous example, executing the command every 5 minutes. Other examples are: */2 would be every 2 mins, */30 every 30 minutes and so on. You can use the same short form for the hour indicator */2 every 2 hours, */6 every 6 hours etc..

 

 

but dosent seem to work

 

So it runs every 6 minutes fine, but if you change it to hours, it runs for every video...correct?

 

It seems like it may be a problem with the cron in the Direct Admin. For whatever reason it is running it at quicker intervals than you want it to. I take it that is your control panel and I would talk to your host about it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.