PHP - Cron Job
Does anyone know how to write the php for a cron job (delete date from a db) this is what I have but it is not doing anything...the cron on my server site runs the code fine but the code does not do anything.
Code: [Select] <?php $date = ('Y-m-d'); //Auto delete // Connect to MySQL $connect = mysql_connect("db","username","password") or die("Not connected"); mysql_select_db("name") or die("could not log in"); // Delete entry where date equals today from the "example" MySQL table mysql_query("DELETE FROM boox WHERE date='$date'") or die(mysql_error()); // ?> Similar TutorialsI am trying to set up a Cron Job. When I run it says that it is inserted. However when I enter my database nothing is in there. Does each part column of a cron job need to be correct for it all to work? For example if I have the code for column corrrect but one wrong will it now work at all? I am a bit lost as to why it says inserted but nothing actually goes into my database. I can manually enter information into the database I can echo it. But I cant Cron Job it in there. Ok, I've been trying to figure this out for about 4 hours now. What I am trying to do is update log information from one table to another every 30 minutes. Am I doing this correct? <?php $cron = true; $userinfo = $db->query( "SELECT * FROM users" ); while ( $pulluserinfo = $db->fetch( $userinfo ) ) { $one .= "" . $pulluserinfo['uID'] . ""; //uID is from the users table $two .= "" .$pulluserinfo['Amount=Amount+1000+(TotalAmount*10)']. ""; //Amount & TotalAmount is from the users table $three .= date("F j, Y, g:i a"); //Putting a date $db->query( "INSERT INTO systemlog (`User`,`Amount`,`Time`) VALUES ('$one', '$two', '$three')" ); } $db->close(); ?> I am having my internship, and i was asked to automate the uploading of file and store the data to MySQL every 8:00am. i've read a lot of articles about crontab/cronjob/php:cron. but i am wondering what is a cron.php and what codes/scripts in that file. i also want to know what is .BAT for. do you have any steps and scripts for my problem? thanks alot.. I am trying to do two cron jobs: I have a program that is set to do a cron job every 15mins to check for imported list staged in the que. But I keep getting an error message:?? sh: line 1: /home/username/sitename.com/8/crons/processimports.php: Permission denied sh: line 2: : command not found this is what I have: Code: [Select] /usr/local/php5/bin/php -q /home/username/sitename.com/8/crons/processimports.php > /dev/null The second one is a scheduler to send out an email, but I get this error message: sh: line 1: /home/username/sitename.com/8/crons/scheduler.php: Permission denied from this out put: Code: [Select] /usr/local/php5/bin/php -q /home/username/sitename.com/8/crons/scheduler.php > /dev/nullPlease Help?? Thanks, TRUSTINWEB I have some cron jobs that pull xml and some webcam images from their respective source sites (NOAA, DOT) and saved to the local server. This is done to ease the strain on the external sites in the event of a user spike on our website. Now, the code works most of the time, but you can see that I dont have any error handling. Sometimes, one of the webcam images will fail to load, and other times I have seen the weather xml feed fail producing some unaestetic php error codes on the site until a half hour later when the cron job runs again. My questions: -Whats the best way to make it try again if it fails? -Are the set time limit statements necessary? I did it as a keep alive. -I also put the sleep statements there to space things out, since there are 6 webcam scripts that run. Anyway, I would appreciate any suggestions. Thanks -Chris Is it possible to have a cron job merely by php ? not by OS (like linux cron). I mean having a php code to repeat a process on with a timer (e.g. every 5min). I'm trying to generate a cron job to run the below script, but can't get it to work for the life of me. Code: [Select] #!/usr/local/bin/php -q <?php if($_GET['key']=="a"){ // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 0){ if($num_results==1){ $message="You have ".$num_results." review unapproved."; } else{ $message="You have ".$num_results." reviews unapproved."; } mail('webmaster@ghosthuntersportal.com','GHP Reviews', $message, 'From: sales@ghosthuntersportal.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 0){ if($num_results2==1){ $message="You have ".$num_results2." RMA Number Requested."; } else{ $message="You have ".$num_results2." RMA Numbers Requested."; } mail('webmaster@ghosthuntersportal.com','GHP RMA Number Requests', $message, 'From: sales@ghosthuntersportal.com'); } echo "Emails Sent."; } ?> Cron Job Command: Code: [Select] php -f /home/zyquo/public_html/ghosthuntersportal.com/cj_run.php?key=a I set the time to run every minute, just to try to get this to work... And in the end I get no emails in my inbox. Hi, I am trying to create a cron job that truncates a database table, then inserts data back into the table, The cron jobs works fine, if i just truncate the table, but does not seem to work if i want to re-insert data back in the table. truncate.php looks as follows: <?php require_once('/usr/www/users/amisea/sosams/db-connecter.php'); $query = "TRUNCATE TABLE tmpsessionmodule; INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module1 FROM session WHERE ((Module1) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module2 FROM session WHERE ((Module2) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module3 FROM session WHERE ((Module3) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module4 FROM session WHERE ((Module4) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module5 FROM session WHERE ((Module5) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module6 FROM session WHERE ((Module6) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module7 FROM session WHERE ((Module7) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module8 FROM session WHERE ((Module8) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module9 FROM session WHERE ((Module9) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module10 FROM session WHERE ((Module10) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module11 FROM session WHERE ((Module11) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module12 FROM session WHERE ((Module12) <>"" );" $result = @mysql_query($query); ?> I have a file called email_cron.php. I have verified that when I load this page in a browser it works fine. I have it doing some email sending, then sending a master email to a specific email address saying what emails were sent. This is an update script for a website to give them notices every day. Regardless, I tested the script itself out and it works perfectly when ran normally. I had setup a cron for this. I thought the cron was working but it's been 3-4-5 days and they have had no emails. If I go in and test the script manually it works but the cron isn't doing something. I am using 1and1.com for the hosting by the way. So I went back into the SSH and typed "crontab -l" and mine is listed. It is marked as 50 * * * * /kunden/usr/local/bin/php /kunden/homepages/##/#######/htdocs/email_cron.php Replace the # with the id's of my site. Which are the path structure. For some reason this isn't working. It shows this when I listed out so I know it's setup as a cron but for some reason it's not running. Did the code I use to set this up not structured right (the 50 * * * * ) part of it or something? I wanted it to run 1 time per day. Thanks again. i have a php script which runs for 3 mins collecting email address and im wondering if i can run this script in the background when a user creates an ad on my website www.corkads.ie ?? I dont want the user to see this script running.. I want the user experence to be the exact same as it is now when they create an ad. but when they click post ad this will initiate a script on another hosting account and it will run by itself.. Kind of like a cron job where the script is running but you cant see it... Hope someone can give me a few ideas on how to do this... Gurus, I have coded for my client a PHP script that performs some extensive data munging on text files he creates. Code is complete and I have now to automate the script. Problem is that it seems to *only* run manually. I won't run as CRON job. This is what I have tried with "#!/usr/bin/php -q" in the header of my script: Code: [Select] 00 1 * * * /usr/bin/php -q /HDDLogs/HDDProcess.php >>/HDDLogs/HDDProcess.log 2>&1 The log file does get created but is empty. I tried removing the -q for quiet mode: no difference. Still did not run. Apache 2.0 and PHP 5.3 is installed on this server. I fully own the directory with my code and the data files are located. Any idea?? Thanks, Al. Sorry maybe a stupid question but Ive made a cron and its not updating the players cash as it should, can anyone spot why? I've looked but just cannot see it, Thanks appreciate your time for looking. Code: [Select] <?php include("server.php"); $sql = "SELECT * FROM players"; $que = mysql_query($sql); while($res=mysql_fetch_array($que)) { $sql2 = "SELECT * FROM players WHERE id = '$res[id]'"; $que2 = mysql_query($sql2) or die(mysql_error()); $res2 = mysql_fetch_array($que2); $hoes = $res2['Hoes']; $hobedding = $res2['MaxHoes']; $incomemod = $res2['HoIncome']; $morale = $res2['HoesMorale']; if ($hoes < $hobedding) { $income = (250 * $hoes * $incomemod * $morale); } else { if ($hoes > $hobedding) { $income = (250 * $hobedding * $incomemod * $morale) + (125 * ($hoes - $hobedding) * $incomemod * $morale); } $sql5 = "UPDATE players SET cash = cash + '$income' WHERE id = '$res[id]'"; mysql_query($sql5) or die(mysql_error()); } } ?> Hi, I need help please with creating a cron job. I have the following sql commands that need to take place within the cron job. This is all i need to do every couple of hours, thus the reason for a cron job. Code below: DELETE FROM tmpsessionmodule; INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module1 FROM session WHERE ((Module1) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module2 FROM session WHERE ((Module2) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module3 FROM session WHERE ((Module3) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module4 FROM session WHERE ((Module4) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module5 FROM session WHERE ((Module5) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module6 FROM session WHERE ((Module6) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module7 FROM session WHERE ((Module7) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module8 FROM session WHERE ((Module8) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module9 FROM session WHERE ((Module9) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module10 FROM session WHERE ((Module10) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module11 FROM session WHERE ((Module11) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module12 FROM session WHERE ((Module12) <>"" ) Can someone please help me!! Any assistance will be greatly appreciated. Thanks! This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347320.0 Hey All, I am using a Curl script to call item details from an API and then updating mysql with the results. But the API is limited to 100 requests per 60 seconds. So I am currently just using: $page = $_GET["page"]; $next_page = ++$page; echo "<meta http-equiv='refresh' content='60;url=?page=".$next_page."'>"; This runs until the results from the API runs out, then resets the page number to 1 and loops through again. My question is, will this would the same with a CRON job?
Hey everyone, So I'm a complete PHP noob and have very basic knowledge of PHP - everything I learn is from tutorials online. I created a website which monitors Stock Exchange data for a particular stock exchange by downloading a CSV file from the Stock Exchange's website containing all the stock data - as this is the only way this particular exchange provides its data to 3rd parties. Now, my PHP system takes this CSV file, reads it and inserts the data into a MySQL database. Then, the function of my site is that users can create alerts for particular stocks that they are watching, and my website will send them an email when the stock price of the stock that they are watching goes above or below a particular value that they specify. Simple! However, since my MySQL database always needs the most recent version of the stock prices, the way I did this in the past was by using Cron every minute to download the file off the exchange's website, and insert the data into my database. I realise that this is quite inefficient, but my main problem is actually that the only way I can do cron every minute is by paying for my own Virtual Dedicated Server as normal shared hosting won't let me run a script that frequently. What I am here to ask is if any of you know an alternative way that I can constantly update the price data in my database i.e. an alternative to cron. I hear that you can run PHP scripts as 'daemons' but I'm not sure how this works nor whether I can do this with normal shared hosting. I cannot afford a Virtual Dedicated server any longer and so need a solution which is compatible with normal, cheap shared hosting. Any help would be much appreciated! Hi guys, Periodically I have a need to execute some local PHP file to clean/update the DB - it takes some parameters. So I use a Cron file, that has WGET statments passing arguments in the URL. The benefit of this is to me is, I can manually via the browser execute the same file. I have been told that using PHP CLI is more efficient, Can anyone shed any light on this? Is it more efficient? Would i be able to manually excecute the PHP CLI file via a browser? Thanks for your thoughts in advance. I am running some php via a cron and I was after the best way to achieve this. Currently I am doing it as follows:- Code: [Select] 0 * * * * lynx -dump http://www.domain.com/script.php This works fine but I don't want anybody being able to run the script by pointing their browser to the file. Any advice on the best method? Cheers. hello im having trouble with this code im not sure if you can help me but ima paste the code here and i will see what people say, the problem is this: PHP Fatal error: require(): Failed opening required '../class/class_db_mysql.php' (include_path='.:') in /var/www/vhosts/dclxvi.co.uk/httpdocs/crons/cron_day.php on line 6 my code is this: <?php include_once ('../Global/config.php'); global $_CONFIG; if($_GET['code'] != $_CONFIG['code']) { die(""); } define("MONO_ON", 1); require "../class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; $db->query("UPDATE fedjail set fed_days=fed_days-1"); $q=$db->query("SELECT * FROM fedjail WHERE fed_days=0"); $ids=array(); while($r=$db->fetch_row($q)) { $ids[]=$r['fed_userid']; } if(count($ids) > 0) { $db->query("UPDATE users SET fedjail=0 WHERE userid IN(".implode(",", $ids).")"); } $db->query("DELETE FROM fedjail WHERE fed_days=0"); $db->query("UPDATE users SET daysingang=daysingang+1 WHERE gang > 0"); $db->query("UPDATE users SET daysold=daysold+1, boxes_opened=0"); $db->query("UPDATE users SET mailban=mailban-1 WHERE mailban > 0"); $db->query("UPDATE users SET donatordays=donatordays-1 WHERE donatordays > 0"); $db->query("UPDATE users SET cdays=cdays-1 WHERE course > 0"); $db->query("UPDATE users SET bankmoney=bankmoney+(bankmoney/50) where bankmoney>0"); $db->query("UPDATE users SET cybermoney=cybermoney+(cybermoney/100*7) where cybermoney>0"); $q=$db->query("SELECT * FROM users WHERE cdays=0 AND course > 0"); while($r=$db->fetch_row($q)) { $cd=$db->query("SELECT * FROM courses WHERE crID={$r['course']}"); $coud=$db->fetch_row($cd); $userid=$r['userid']; $db->query("INSERT INTO coursesdone VALUES({$r['userid']},{$r['course']})"); $upd=""; $ev=""; if($coud['crSTR'] > 0) { $upd.=",us.strength=us.strength+{$coud['crSTR']}"; $ev.=", {$coud['crSTR']} strength"; } if($coud['crGUARD'] > 0) { $upd.=",us.guard=us.guard+{$coud['crGUARD']}"; $ev.=", {$coud['crGUARD']} guard"; } if($coud['crLABOUR'] > 0) { $upd.=",us.labour=us.labour+{$coud['crLABOUR']}"; $ev.=", {$coud['crLABOUR']} labour"; } if($coud['crAGIL'] > 0) { $upd.=",us.agility=us.agility+{$coud['crAGIL']}"; $ev.=", {$coud['crAGIL']} agility"; } if($coud['crIQ'] > 0) { $upd.=",us.IQ=us.IQ+{$coud['crIQ']}"; $ev.=", {$coud['crIQ']} IQ"; } $ev=substr($ev,1); if ($upd) { $db->query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid"); } $db->query("INSERT INTO events VALUES('',$userid,unix_timestamp(),0,'Congratulations, you completed the {$coud['crNAME']} and gained $ev!')"); } $db->query("UPDATE users SET course=0 WHERE cdays=0"); $db->query("TRUNCATE TABLE `votes`"); ?> i have a php script that works perfectly by sending an new image to twitter api. when i set a cron job it doesn't work. is there any reason for this please? thanks Code: [Select] if ( ! empty($_FILES)) { require 'tmhOAuth.php'; require 'tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array( 'consumer_key' => deleted, 'consumer_secret' => deleted, 'user_token' => 'deleted, 'user_secret' => deleted, )); $params = array('image' => "@temps/now.JPG;type=image/jpg;filename=now",); $code = $tmhOAuth->request('POST', $tmhOAuth->url("1/account/update_profile_image"), $params, true, // use auth true // multipart ); } |