PHP - Moved: Standard Question About Cron Jobs.
This topic has been moved to Linux.
http://www.phpfreaks.com/forums/index.php?topic=306518.0 Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=333230.0 PHP + MySQL This has been doing my head in, it has to be possible how I think it is. The thing I am trying to achieve here is let's say a list of users logged in. Now if every one would click logout and use the system correctly the world would be a better place, but they wont, we all know this. So I was thinking how to counter this and I came up with an idea, lets say in our users table we have an "ACTION" field as a timestamp (or datestamp??). So everytime the user does anything on my site, edit there profile, browse something etc etc, it updates the "ACTION" field to the current time. I was thinking in the background I could have a cron job run every.. 5 minutes? Is it possible to have it check EVERY users ACTION field and if there ACTION field is less than the current time - 5 minutes, it updates there LOGGED_IN field to like 0, which would mean they're actually not logged in anymore and would not appear in the logged in list. Someone tell me yes or no! (The main problem being having to constantly update that ACTION field) 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`"); ?> Hello there.. my webhost doesn't have Cron Jobs feature.. is there any alternative php script in able to run my php script every minute ?? i have a website containing mafia game.. it's coded in php.. i tried to use Code: [Select] <META HTTP-EQUIV="Refresh" CONTENT="60; URL=http://test.com/run_minute.php">but this will work only if the user is in the existing page where this code placed.. i want it something like, the http://test.com/run_minute.php will refresh every minute.. even thou the user is not on the page.. Thank you. More power.. Basically I am setting up my own cricket management game, but there are 3 areas that I am slightly stuck on and would appreciate help: 1) When a use registers, I need to create 11 players for their team. For this, I am going to have one text files with first names and one text file with surnames. How can I open each file and select a name and then match them together? 2) I need to create the list of games to be executed at particular times through a cron job. How can I go through all the teams in a table and match them together in games, ensuring everyone plays everyone? If a new player registers, he will be put into a random league and so the games for that league will have to be redone 3) How can I set up a cron job to execute the above games? Each team should play once a day and so if there are 24 teams in a table, there will be 12 games that occur through this cron job. I assume cron jobs are the best thing for this. Any help would be appreciated. Thanks. This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=320840.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=346652.0 This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347320.0 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... This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=334310.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=331038.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321924.0 This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=317079.0 This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=346879.0 This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 Hey..
So lately I've been hooking up large requests to resque jobs in my application, for the purpose of not keeping the user(s) waiting for a longer period of time before they can continue using the application. At the same time, I have a frontend library & eventlistener alerting the users when any specific job was actually completed by the workers. I have realized however that in some cases, this doesn't pan out.
I love the idea of resque jobs, but my gut feeling is that I somehow lose control of the request I'm processing. The reason I'm posting this is because there's one part of my application that processes an insane amount of data, in a loop(!). Obviously this can take a long time, and that's to be expected. But when an error occurs along the way, I have no good way of logging it nor alerting the user about it.
Picture a scenario where a Worker is doing a Job that would take 2 minutes, and is 80% done, at which point it fails for whatever reason. How would you recommend something like this to be handled?
Obviously I get internal logs from the jobs the workers perform, but more specifically how would you catch the errors right from the script? Currently this is my setup...
try { ...//code that takes > 1min } catch(AppException $error) { ...//Internal code error, catch } catch(SeqDbException $dbError) { ..//DbError or Query } catch(SystemException $exception) { ..//More severe exceptions }Either I'm missing a catch, or I'm missing something else. The errors rarely occur as well, so it's not easy for me to debug it or re-create them. It's very dependent on the data that is being processed. Hi guys, I am trying to get data from the table "jobs" and insert its id and name into table "bookings" I can get the job "name" from "jobs", which is fine, using the following: <select class="form-control" id="tour_name" name="tour_name"> <option value="Select">== Select Tour or Charter ==</option> <?php $sql = "SELECT name FROM jobs"; $result = $con->query($sql); while(list($name) = mysqli_fetch_row($result)){ ?> <option value="<?php echo $name ?>"><?php echo $name;?></option> <?php } ?> </select> However, when I click submit to insert into "bookings" everything goes in except "booking_id" which is "id" in "jobs". Hope this makes sense. I am using the following to insert: if(isset($_POST['new']) && $_POST['new']==1){ $sql = "SELECT id FROM jobs"; $result = $con->query($sql); while(list($id) = mysqli_fetch_row($result)){ } $tour_id = isset($_GET['id']) ? $_GET['id'] : ''; $tour_name = mysqli_real_escape_string($con, $_POST['tour_name']); $customer_name = mysqli_real_escape_string($con, $_POST['customer_name']); $customer_address = mysqli_real_escape_string($con, $_POST['customer_address']); $customer_email = mysqli_real_escape_string($con, $_POST['customer_email']); $customer_phone = mysqli_real_escape_string($con, $_POST['customer_phone']); $total_pax = mysqli_real_escape_string($con, $_POST['total_pax']); $status = mysqli_real_escape_string($con, $_POST['status']); $order_at = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $total_amount = mysqli_real_escape_string($con, $_POST['total_amount']); $query="insert into bookings (`tour_id`, `tour_name`, `customer_name`, `customer_address`, `customer_email`, `customer_phone`, `total_pax`, `status`, `order_at`, `total_amount`)values ('$tour_id', '$tour_name', '$customer_name', '$customer_address', '$customer_email', '$customer_phone', '$total_pax', '$status', '$order_at', '$total_amount')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Record Inserted Successfully</p>'; } } Can anyone please lend a hand with this? 2 Days at it now and ready to hit the Guinness.
Cheers, Dan I am looking at a website which will have a number of items on it advertised,such as:
businesses
jobs
property
etc
what I want to know is when designing the database would you have these in one table or a table for each?
Edited by brown2005, 14 October 2014 - 08:43 AM. This is the simplest of forms, but it has no character. It is the type I use in everything. form1.php <html> <head> </head> <body> <?php // Connect to database===================================================== include("connect_db.php"); // retrieve form data ====================================================== $id = $_POST['id']; // sending query =========================================================== $query = "SELECT ama,model_name,model_mfg,wingspan,engine,decibels FROM airplanes WHERE id='$id'"; if( !$result = mysql_query($query) ) { echo "<br>Query $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $fetch = mysql_fetch_array( $result ); } // $fetch = mysql_fetch_array(mysql_query("SELECT ama,model_name,model_mfg,wingspan,engine,decibels FROM airplanes // WHERE id='$id'")); // Output form with retrieved data ========================================== ?> <h3>Change the data and then click the CHANGE button</h3><br> <form name="myForm" action="delete_airplanes.php" onsubmit="return validateForm()" method="post"> ID #:<input type="text" name="id" value="<?=$fetch[id]?>" /><br> AMA #:<input type="text" name="ama" value="<?=$fetch[ama]?>" /><br> Model Name:<input type="text" name="model_name" value="<?=$fetch[model_name]?>" /><br> Model Mfg:<input type="text" name="model_mfg" value="<?=$fetch[model_mfg]?>" /><br> Wingspan:<input type="text" name="wingspan" value="<?=$fetch[wingspan]?>" /><br> Engine:<input type="text" name="engine" value="<?=$fetch[engine]?>" /><br> Decibels:<input type="text" name="decibels" value="<?=$fetch[decibels]?>" /><br><br> <input name="submit" id="submit" value="CHANGE!" type="submit"> </form> <br> <body> </html> I would love to be able to get this form to work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Enter Airplane Data</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="language" content="en" /> <style type="text/css"> .focus { background: #FEF1C1; } .class123-label { font-family: Verdana; font-size: small; } .class123-sidebyside { float:left; margin:0 5px 0 0;} .class123-twocol { float:left; width:45%; margin:0 5px 0 0;} .class123-threecol { float:left; width:30%; margin:0 5px 0 0;} .class123-likert_style_li { display:inline-block; vertical-align:middle; text-align:center; top:0px; padding:2px; width:64px; height:50px; margin:0px; margin-right:1px; margin-bottom:1px; font:11px/18px verdana; background:#ddd; zoom:1; *display:inline; } .class123-likert_style_li2 { display:inline-block; vertical-align:middle; text-align:center; top:0px; padding:2px; width:64px; height:50px; margin:0px; margin-right:1px; margin-bottom:0px; font:12px/18px verdana; background:#fff; zoom:1; *display:inline; border-top:1px solid #ddd; } .fontbold { font-weight: bold; } .fontitalic { font-style: italic; } .requiredspan { font-family: Verdana; font-size:10px; color:#f00; } </style> </head> <body style="background-color: rgb(138, 174, 222); direction: ltr;"> <div style="height: 50px;"> </div> <center> <table style="border-collapse: collapse;" id="AutoNumber1" border="0" cellpadding="0" cellspacing="0" width="658"> <tbody> <tr> <td class="tdborder" colspan="3" width="658"> <img alt="shadow" class="tdimagesus" src="/templates/cache/dynamicimage-1-1560BD.png" height="9" width="100%" /> </td> </tr> <tr> <td height="38" width="4"> </td> <td class="tdheader" style="border-style: solid solid none; border-color: rgb(1, 76, 169) rgb(1, 76, 169) -moz-use-text-color; border-width: thin thin medium;" bgcolor="#1560bd" height="38" width="650"> <img alt="logo" src="http://www.123contactform.com/templates/logos/computers_anvelope_white.png" align="left" /> </td> <td height="38" width="4"> </td> </tr> <tr> <td height="171" width="4"> </td> <td class="tdmain" style="border-style: none solid; border-color: -moz-use-text-color rgb(1, 76, 169); border-width: medium thin; padding-right: 10px;" bgcolor="#ffffff" height="171" width="650"> <div class="selector-off"> <center> <script type="text/javascript"> <!-- function InputActions(field,id) { var i=1; var lid="none"; for (i=1;i<=100;i++) { lid='row'+i; lidsec='rowsec'+i; if (document.getElementById(lid) != null) { if (lid==id) { document.getElementById(lid).className='focus'; if (document.getElementById(lidsec) != null) document.getElementById(lidsec).className='focus'; } else { document.getElementById(lid).className=''; if (document.getElementById(lidsec) != null) document.getElementById(lidsec).className=''; } } } } //--> </script> <form class="form" action="http://www.123contactform.com/contact-form-crmamx-122034.html" method="post" enctype="multipart/form-data"><input name="action" value="verify" type="hidden" /> <table style="min-width: 250px;" cellpadding="4"> <tbody> <tr id="row1"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684273" for="id123-control684273">Name:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684273" name="control684273" onclick="InputActions(this,'row1');" onkeyup="InputActions(this,'row1');" onchange="" value="" size="20" type="text" /> </td> </tr> <tr id="row2"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684275" for="id123-control684275">Subject:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684275" name="control684275" onclick="InputActions(this,'row2');" onkeyup="InputActions(this,'row2');" onchange="" value="" size="20" type="text" /> </td> </tr> <tr id="row3"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684281" for="id123-control684281">Model Name:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684281" name="control684281" onclick="InputActions(this,'row3');" onkeyup="InputActions(this,'row3');" onchange="" value="" size="35" type="text" /> </td> </tr> <tr id="row4"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684286" for="id123-control684286">Model Mfg:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684286" name="control684286" onclick="InputActions(this,'row4');" onkeyup="InputActions(this,'row4');" onchange="" value="" size="35" type="text" /> </td> </tr> <tr id="row5"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684287" for="id123-control684287">Wingspan:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684287" name="control684287" onclick="InputActions(this,'row5');" onkeyup="InputActions(this,'row5');" onchange="" value="" size="35" type="text" /> </td> </tr> <tr id="row6"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684288" for="id123-control684288">Engine Mfg/Size:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684288" name="control684288" onclick="InputActions(this,'row6');" onkeyup="InputActions(this,'row6');" onchange="" value="" size="35" type="text" /> </td> </tr> <tr id="row7"> <td style="text-align: left;" valign="top"><label class="class123-label" id="id123-title684289" for="id123-control684289">Decibel Reading:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td style="" align="left"><input id="id123-control684289" name="control684289" onclick="InputActions(this,'row7');" onkeyup="InputActions(this,'row7');" onchange="" value="" size="35" type="text" /> </td> </tr> <tr id="row8"> <td style="text-align: left;" valign="top"><label class="class123-label" for="id123-captcha" id="verifno">Verification No.:</label><span class="requiredspan customspan" title="Required field">*</span></td> <td align="left" valign="top"><input id="id123-captcha" onclick="InputActions(this,'row8');" onkeyup="InputActions(this,'row8');" name="txtNumber" value="" size="16" type="text" /></td> </tr> <tr> <td align="right"><a title="Don't know why you have to enter this verification number? Click here!" href="http://www.123contactform.com/faq.html#q1" onclick="window.open('http://www.123contactform.com/faq.html#q1','_blank','width=740, height=90, left=' + (screen.width/2-370) + ', top=250');return false;"><img src="http://www.123contactform.com/img/help_icon.gif" alt="contact form faq" border="0" /></a></td> <td align="left"><img alt="verification image" src="http://www.123contactform.com/random.php" /></td> </tr> <tr> <td></td> <td align="left"><input class="class123-button" id="id123-button-send" value="Send email" type="submit" /></td> </tr> </tbody> </table> <div style="height: 1px; display: none; visibility: hidden;"> <input name="email" type="text" /></div> </form> </center> </div> </td> <td height="171" width="4"></td> </tr> </tbody> </table> </center> </body> </html> Of course I did not write this. I have never used a form before built as a table, only like the form1.php 1. Does this form work in the same way? 2. I want to retrieve a record from the db and display it in this form. Do I do it in the same way as in form1.html with a value=? 3. If the above is true then I would assume (that always gets me in trouble) that in my next program (update_db.php) I would capture the input data the same. Thanks I am looking to finally move to a popular coding style. Anyone know any great ones I should look into? So far I have looked into PEAR. Thanks! |