PHP - Php Script Issue With Cron
Hello,
I have a php script that I'm trying to have run from a different server via cron Code: [Select] 1 9 * * * /usr/bin/wget wget -o http://www.site1.com/update.php -o /dev/null The log in /var/log/cron is showing this as having been run: Code: [Select] Dec 26 09:01:01 host crond[10392]: (root) CMD (/usr/bin/wget wget -o http://www.site1.com/update.php -o /dev/null) Dec 27 09:01:01 host crond[17001]: (root) CMD (/usr/bin/wget wget -o http://www.site1.com/update.php -o /dev/null) Dec 28 09:01:01 host crond[2331]: (root) CMD (/usr/bin/wget wget -o http://www.site1.com/update.php -o /dev/null) however it does not appear to run successful (or at least nothing gets updated) Here is the update.php <?php require_once('functions.php'); mysql_connect("localhost","username","password"); mysql_select_db("database"); $result = mysql_query("SELECT * FROM ServerList"); while($row = mysql_fetch_array($result)){ $server = new Whm; $server->init($row['HostName'],$row['UserName'],$row['PassHash']); $NewUsedSlots = count($server->listaccts()); mysql_query("UPDATE ServerList SET UsedSlots='$NewUsedSlots' WHERE HostName='{$row['HostName']}'"); } $CurrentTime = date("Y-m-d G:i"); mysql_query("UPDATE UpdateTime SET TimeUpdated='$CurrentTime'"); ?> update.php does in fact work correctly when I run it from my own personal browser.. what is going wrong? thanks! Similar TutorialsGurus, 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. 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. Hi
I've been stuck trying to execute a script for a few weeks now and I really need help.
The script is supposed to schedule social media posts via functions.php and wp-load.php but I get errors.
Can someone do me a favour?
Drop your email and I'll send you the details to connect to my database.
Thanks
I've got a script that's been running away happily as a cron job for the last few days, but it's suddenly decided to stop working. When I run the script manually it works perfectly, but not when I run it as a cron job. I've done some debugging and I've found that the cause of the problem appears to be an ftp_get function that I'm using. I'm guessing I need to either change a file path, or a file permission, but I'm not sure to what. Here's the info: Code: [Select] $local_dir = '../../col_protected/'; $c = ftp_connect('www.mydomain.net') or die("Can't connect"); ftp_login($c,'ftp_username','ftp_password') or die("Can't login"); ftp_get($c, $local_dir.$filename, FTP_ASCII) or die("Can't transfer"); The FTP connect and login are still working fine, it's the ftp_get that's causing the problem. The '../../col_protected/' directory is on the same level as the public_html (ie. outside the public_html) with file permissions set to 777. The cron is running at /home/username/public_html/col/proc1.php Can anyone advise please? Many thanks, Chris Code: [Select] $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 1){ $message="You have ".$num_results." reviews unapproved."; mail('example@example.com','GHP Reviews', $message, 'From: example@example.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 1){ $message="You have ".$num_results2." RMA Numbers Requested."; mail('example@example.com','GHP RMA Number Requests', $message, 'From: example@example.com'); } The reviews email is being sent, however, the RMA email is not. EDIT: Nevermind, $num_results and $num_results2 should have been > 0 not > 1. Guys Im having a strange issue with my code I have a form to request a password to be sent to email incase forgotten The script seems to run as it should as in taking the info then redirecting to the messages page for confirmation no problem but its not sending the email Ive checked and double checked, and even re written the code from scratch and nothing seems to be playing ball in sending the email Can someone shed some none sleep deprived eyes over it and point out what will no doubt be an obvious error I just cant seem to see The Form: Code: [Select] <form name="sendpw" method="post" action="sendpw.php"> <br> <table width="100%" border="0" class="tbl"> <tr> <td width="198"><div align="right">Username:</div></td> <td width="418"><input name="name" type="text" class="input" size="30"></td> </tr> <tr> <td><div align="right">Email: </div> </td> <td><input name="mail" type="text" class="input" size="30"></td> </tr> <tr> <td colspan="2"> <div align="center"> <input name="Submit" type="submit"> </div></td> </tr> </table> </form> The Script: Code: [Select] <? include ('config.php'); $name=$_POST['name']; $em=$_POST['mail']; $query="SELECT pw FROM user WHERE uname='$name' AND email='$em'" or die (mysql_error()); $result= mysql_query($query); $row = mysql_fetch_assoc($result); $pass=$row['pw']; $to="$em"; $from="From: passwords@MBD.net"; $msg="Username: $name\r\n"; $msg .="Password: $pass\r\n"; $msg .="Please keep this password safe"; $subject="Your Login Password\r\n"; mail($to,$subject,$msg,$from); header( "Location:messages.php?msg=2" ); exit(); ?> config.php is just my database connection info, which is working fine as it runs all all my pages that access the database. Thanks Tom I'm using XAMPP and im a major noob. Last nite I was following this tutor and the connection script that was on it didnt work for me. So today I tried a connection script from another tutor on another site that worked just fine. here is the script that worked I saved it as test.php and went to localhost/test/php and it loaded a page connected to mysql <?php mysql_connect("localhost", "shadowing", "eguitars8") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> The script that didnt work i saved it as connect.php and went to localhost/connect/php and it gave me a page saying "Object not found error "the request url was not found on this server." I understand this script doesnt have a echo on it but shouldnt it still take me to a blank white page instead of a error page. Or is there something wrong with it. Really appreciate any help with this. the script that didnt work is below <?php $mysql_server = "localhost"; // localhost is common on most hosts. $mysql_user = "shadowing"; // this is the name of your username of the server. $mysql_password = "eguitars8"; // the password connected to the username. MAKE IT COMPLEX. $mysql_database = "spacewars"; // the database name of where to connect to and where the information will be help. $connection = mysq1_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection"); $db = mysql_database("$mysql_database") or die ("Unable to establish a DB connection"); ?> It seems something has changed at Yahoo Finance. I use a Stock quote script (micro stock) to post stock quotes from specific tickers on my website. It worked fine for years until recently. Now i am unable to access any data directly from any Yahoo finance URL. Hereafter my script which comes from 1) Micro Stock : http://www.phptoys.com/product/micro-stock.html or 2) Getting Stock Quote : http://www.phptoys.com/tutorial/getting-stock-quote.html <?php function getStockSite($stockLink){ if ($fp = fopen($stockLink, 'r')) {$content = ''; while ($line = fread($fp, 1024)) {$content .= $line;}} return $content;} function processStockSite($wurl){ $wrss = getStockSite($wurl); $text = ''; if (strlen($wrss)>100){ // Get text $spos = strpos($wrss,'</span>:',$spos)+3; $spos = strpos($wrss,'<big>',$spos); $epos = strpos($wrss,'</div><h1>',$spos); if ($epos>$spos){ $text = substr($wrss,$spos,$epos-$spos);} else {$text = '-';}} // Get results $result['text'] = $text; return $result;} <html> <head> <title>Get Stock tutorial</title> </head> <body> <?php // Get stock data $data = processStockSite('http://finance.yahoo.com/q?s=GOOG'); echo $data['text']; ?> I am not php programmer and i hope someone can help me in this matter since that script was a marvel. Thank in advance. Hello, I am writing a data retrieval script, in order to print data stored in a DB. For some reason the script does not work.. More details below.. Code: [Select] the form that calls the initiator script.. <form method='get' action="init.Get.php"> <div><input type="submit" name="get" value="See Data"></div> </form> Code: [Select] the initiator script <?php include 'dataGet.class.php'; $data= new getData(); $data= getData($name, $email, $text); ?> Code: [Select] my class.. <?php class getData { private $name; private $email; private $text; function __construct(){ $this->host = 'localhost'; $this->uname = 'root'; $this->pword = '1111'; $this->dbname = 'teststorage'; $this->dbtable = 'userData'; } function getData($name, $email, $text){ $this->dbconnect = mysql_connect($this->host, $this->uname, $this->pword); if (!$this->dbconnect) die("Connection Unable " . mysql_error()); mysql_select_db($this->dbname); $sql_query = "SELECT * FROM $this->dbtable "; $result = mysql_query($sql_query); if ($result){ echo $result; } else{ echo "Retrieval Unsuccesful"; } mysql_close($sql_query); } } ?> Can someone please tell me what am I doing wrong? Thank you in advance. Hi all, Sorry to be a pain, but I've been out of the php game for quite a few years and have just come back to it briefly to help someone out. I've been using an old admin auth script that I used to use a long time ago but it's not working, and I can't for the life of me work it out :/ I apologise for the noobishness of the code, but as I said, it's been a long time. Any and all help would be very greatly appreciated. Here is the code: <? require("config.php"); mysql_connect($server,$login,$password) or die('Error connecting to server'); mysql_select_db($base) or die('Error connecting to database'); $req = mysql_query("SELECT username,mempass,level FROM members WHERE username='$admin_login'"); $data = @mysql_fetch_array($req); $member_name = $data["username"]; $member_pass = $data["mempass"]; $member_userlevel = $data["level"]; if($member_pass == $admin_pass) { SetCookie("mgdwebby","$member_name:$member_pass:$member_userlevel"); } include("header.php"); ?> <? if($action=="login") { if($admin_login==""){ echo"Wrong info. "; } elseif($admin_pass==""){ echo"Wrong info. "; } else{ require("config.php"); mysql_connect($server,$login,$password) or die('Error connecting to server'); mysql_select_db($base) or die('Error connecting to database'); $req = mysql_query("SELECT username,mempass,level FROM members WHERE username='$admin_login'"); $data = @mysql_fetch_array($req); $member_name = $data["username"]; $member_pass = $data["mempass"]; if($member_pass == $admin_pass) { echo"<head><meta http-equiv=\"refresh\" content=\"2;URL=admin.php\"></head><br><center>Please Wait.</center><br>"; $auth = explode(":",$HTTP_COOKIE_VARS["mgdwebby"]); if(empty($auth[0]) || empty($auth[1])) { } else { echo"Welcome<br>"; include("admin_left.php"); } } else { echo"Wrong info. "; } } } else { echo"<form method='post' action='?action=login'> <table width='307' align='center' cellspacing='0' cellpading='0' border='0'> <tr> <td width='200'> Login : </td> <td> <input type='text' name='admin_login'></td> </tr> <tr> <td width='200'> Password : </td> <td> <input type='password' name='admin_pass'></td> </tr> <tr> <td colspan='2' align='center'><center><input type='submit' value='Login'></center></td> </table> "; } ?> <? include("footer.php"); ?> a douche hard coded my shopping carts VAT to 17.5% i wanted to just adjust the VAT in the shopping cart, but he has removed the feature.. so what i was thinking to counter it, was to make a php script that could EDIT all the prices in the database +2.5% can anybody help me with this please? 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. 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 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 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.. 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()); // ?> 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 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. Over the past few days I have been running into some issues with my server crashing due to apache max connections issues. I am running my site off of a hosted Cloud VPS with 200GB of storage, 8192MB Memory, 8TB of transfer, Apache, MySQL, PHP5, and CentOS.
I am afraid the issue doesn't necessarily lay in the configuration of Apache, but the way I have scripted the php on my site, the reason I am reaching out here. My site isn't your average website, it is more of a web-based customer management program. There are currently only 2 pages you can actually access via the url bar (signin.php and index.php). All other content is loaded via AJAX and JQuery processes (.load and $.getScript).
All AJAX requests are pointed toward a single file called functions.php where a _POST parameter contains the function name and any additional _POST data required by the function.
FOR EXAMPLE:
AJAX Call:
$.post('functions/functions.php',{func:'myFunctionName',ops:'whatever',a:'whatever',b:'whatever'},function(data){ DO WHATEVER I WANT WITH THE RETURN DATA HERE },"json");PHP (functions.php) require 'dbcon.php'; include 'main_class.php'; include 'f_customerdetail.php'; include 'f_listoptions.php'; include 'f_route.php'; include 'f_useractions.php'; if (isset($_POST['func'])){ $userfunc = $_POST['func']; $funcops = $_POST['ops']; if ($funcops != ''){ $userfunc($funcops); }else{ $userfunc(); } } |