PHP - Correct Way Of Doing A Php Timeout
I was wanting to make some kind of session timeout ability, just purely out of curiosity.
I have tried going off my own theory, before looking at any tutorials, well have looked a bit but tried getting the jist and having a go myself the next day (anyways that being said), this code he Code: [Select] <?php ini_set('display_errors', 1); session_name("jeremysmith_test_session"); session_start(); $_SESSION['start_time'] = time(); if($_SESSION['start_time'] < $_SESSION['start_time'] + 500) { printf("Time out be out dated!"); } Just does not seem to want to work, is there any reason for this, that you could think of? I appreciate any replies, Jeremy. Similar TutorialsIt's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); Hi I am trying to create a "User logged" function that tells the database when the user was logged in, I have heard about creating a time out for this, but dont have any idea how to do it or what it does! Any one have any ideas? Thanks Rhys I am trying to transfer a large amount of data from a text file exported from a Microsoft Access database into a MSQL database. I have written a script in PHP to open the text file, read a line at a time, sort out the data for insertion into a new table and then insert the data into the table in the MSQL database. This works perfectly for 3 or 100+ records, so the fundamentals appear to be solid. The problem starts when I try to do all the records - about 33,500. I get: Fatal error: Maximum execution time of 30 seconds exceeded in C:\DATA\HTMLServedDocs\MusicIndex\MusicImport.php on line 40. Line 40 is the database write: $result = mysqli_query($dbc, $query); I'm not sure if the root of the error is the Web Server, the Database or something else. I am using the Abyss server, which while it is a bit clunky it is appropriate for the application. Does anyone have any ideas how to get around this problem. I could split the data up into smaller files but that is not ideal. So i have this script that connects to a game data base and it must select and make a top of some columns in data base. The thing is if the data base is offline then the script kinda blocks the website because it has no timeout option. How can i add like a $timeout=2 (in seconds) thing..so if after 2 seconds it gets no connection the script is killed Thanks in advance <?php $database_info = array( 'host' => '___', 'user' => '___', 'password' => '___', 'l2jdb' => '___' ); @mysql_connect($database_info['host'], $database_info['user'], $database_info['password']) or die(mysql_error()); @mysql_select_db($database_info['l2jdb']) or die(mysql_error()); echo "<table class=\"pvp\">"; $query = "SELECT * FROM characters WHERE accesslevel = 0 ORDER BY pvpkills DESC limit 10"; //change 10 to whatever amount you want to show on your website. $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $name = $row['char_name']; $pvpscore = $row['pvpkills']; // Inserting data into the table echo " <tr> <td width=\"110\"><strong> $name</strong></td> <td width=\"50\"><div align=\"center\">$pvpscore</div></td> </tr>"; } echo "</table>"; //closing mysql connection mysql_close(); ?> Okay, I'm not quite sure how to state this, so I'll try my best. Is it possible to setup some kind of "after so long, it changes the state of something from 'fighting' to 'active'" query or function? What is happening is that people are fighting in my game, then choosing to just close their browser rather than quit the fight, to change the monster's state back to 'active', so other people can fight it. Does that make sense? Any thoughts or could someone point me in the right direction? Thanks!! I am using this code to check if a server is running. Everything is fine when it is running, but when it's not, it takes ages for the fsockopen to fail. Is there a way to make it timeout faster? if (fsockopen($settings->survival_server, $settings->survival_port, $timeout = 0.1)){ $survival['status'] = "Up"; }else { $survival['status'] = "Down" } I have a site up where my client can enter some text in a box, and save it to a database. But the page keeps timing out. I can't get it to happen in Firefox or Chrome so it leads me to believe that its a setting in IE? This is what I have tried: set_time_limit(0) which i understand sets the time limit for the script to unlimitted. ini_set("session.use_cookies", 1); ini_set("session.cookie_lifetime", 0); Turns cookies on, and makes them last forever. session_set_cookie_params(3600); Makes a cookies last for an hour. I have tried all of these, and I have tried them in pieces. [EDIT] I do places all before session_start I have read that some of this can go into the php.ini file, but I cannot figure out exactly what I am supposed to add? Our current php.ini is the default: * CODE ******************************************************************************* register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" ; Only uncomment zend optimizer lines if your application requires Zend Optimizer support ;[Zend] ;zend_optimizer.optimization_level=15 ;zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3 ;zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3 ;zend_extension=/usr/local/Zend/lib/Optimizer-3.3.3/ZendExtensionManager.so ;zend_extension_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3/ZendExtensionManager_TS.so ; -- Be very careful to not to disable a function which might be needed! ; -- Uncomment the following lines to increase the security of your PHP site. ;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru, ; phpinfo, exec, system, dl, fsockopen, set_time_limit, ; popen, proc_open, proc_nice,shell_exec,show_source,symlink" * CODE ******************************************************************************* Where do I go from here? What is my next step? Thanks for taking the time to read my post, and thanks for the help! Nick Ok i know the default session timeout is set to 25 minues if they are idle, but will it still timeout if the are on a constant refresh page, like if the page there on refreshes every minute will they time out after the 25 still. Hi,
I have a heavy php page that is timing out at 30 seconds. I do not have access to change/set any ini or max_execution_time or the like. I need to find some creative workaround. First, I looked at async calls, but I'm using Yii 1.1 at the moment and it didn't look like simple to implement when I had a quick glance at that. Is it possible to load the content via ajax instead? I've been getting this error: Fatal error: Maximum execution time of 30 seconds exceeded in... (gives file and line number) I've cut out most of the code in the for loop to narrow it down specifically to the $i variable messing it up somehow... The 2nd part of the if statement where I try to append the $i variable to the new $row_ variable is causing it to hang like this. I want to be able to make 5 new variables... $row_1...$row_2...etc... but for some reason when I try to append the $i to it, it hangs. and throws that error eventually. Does anyone know why it does this? Any help is appreciated. Thank you! Code: [Select] for ($i=1;$i<6;$i++){ if ($row['bef_remarks' . $i] != "Description"){ $row_.$i = 1; Hi Im trying to keep a session open once a user logs in for a large amount of time ( months) I have set the following in a .htaccess file php_value session.cookie_lifetime 99999999 php_value session.gc_maxlifetime 99999999 But i still lose the session and get logged out after 10 minutes or so i have created a phpinfo page and see that for these values the following is set session.cookie_lifetime 99999999( local) 0 (global) session.gc_maxlifetime 99999999 ( local) 1440 (global) What is the difference between the local and global? Any other ides why might session keeps timing out after 10 mins or so of inactivity? Hi there. How do I stop a function from running it it's taking to long to proccess. For example, say after 10 seconds the code is still working I display an error message? As you can in the following code it's pulling the contents from an url or file which might take too long to load. function Tester($url); { return file_get_contents($url); } Thanks a mil Hey I was wondering is there a way I can set my sessions to timeout/end a session after a certain amount of time? Here is what I am dealing with... Code: [Select] <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> As the title says, I have a .txt file with about 30,000+ lines of data presented in a pipe delimited list, which i'm parsing and inserting into my database. Problem is, my server seems to always time out every time I try to parse the whole file at once. I'm sure naturally it would work with out any timeout errors, but i'm ensuring the data is xss clean before it's being inserted and i'm doing that on about 15 items on each line, which means i'm calling the xss clean function over 450,000 times in one execution. So my friend suggested I break the files down maybe into each file having 5,000 lines of code, which would mean i'd generate about 6 files (if I had 30,000 lines of data). I've managed to code a script that breaks the main file into several files. Now what I want to do is pass each of those files to my parser method, but i'd like to do them one by one, rather than in one execution as I want to avoid the timeout error. Any ideas? Hi, I have created a script that connects to an FTP SERVER... downloads a movie file to the web server then uploads it to a target FTP server. If I move a small file of say 10mb it works well! But if I move a larger moviefile such as a 700mb file it doesn't... The only thing I can think is there is some sort of timeout... Any pointers would be a massive help! I have tried to increase the FTP timeout and also enabled passive mode Code: [Select] ftp_set_option($conn2, FTP_TIMEOUT_SEC, 600); Code: [Select] <?php $movefile = "movie 2.avi"; $server1 = array( "Name" =>"Downloads", "Host" =>"10.0.1.3", "User" =>"Paulio", "Pass" =>"lol", "Path" =>"/Download/Completed"); $server2 = array( "Name" =>"files", "Host" =>"10.0.1.2", "User" =>"Paulio", "Pass" =>"lol", "Path" =>"/Television"); ////////////////////////////////// Download file to be moved. ////////////////////////////////// // Connect to server $conn1 = ftp_connect($server1['Host']); // Open a session to an external ftp site $login1 = ftp_login ($conn1, $server1['User'], $server1['Pass']); ftp_pasv($conn1, true); // Check open if ((!$conn1) || (!$login1)) { echo "Ftp-connect failed!"; die; } else { echo "Connected to " . $server1['Name'] . " FTP server.<br><br>"; } [b]ftp_set_option($conn1, FTP_TIMEOUT_SEC, 600);[/b] ftp_chdir($conn1, $server1["Path"]); // Moves file to be moved to web NAS drive. ftp_get($conn1, $movefile, $movefile, FTP_BINARY); ////////////////////////////////// Upload file to be moved. ////////////////////////////////// // Connect to server $conn2 = ftp_connect($server2['Host']); // Open a session to an external ftp site $login2 = ftp_login ($conn2, $server2['User'], $server2['Pass']); ftp_pasv($conn2, true); // Check open if ((!$conn2) || (!$login2)) { echo "Ftp-connect failed!"; die; } else { echo "Connected to " . $server2['Name'] . " FTP server.<br><br>"; } [b]ftp_set_option($conn2, FTP_TIMEOUT_SEC, 600);[/b] ftp_chdir($conn2, $server2["Path"]); // Uploads moved file from web NAS drive to destination ftp_put($conn2, $movefile, $movefile, FTP_BINARY); //Deletes source file ftp_delete($conn1, $movefile); //Deletes temp file unlink($movefile); ftp_close($conn1); ftp_close($conn2); echo "Complete."; ?> Thanks, Paul. I have 500 users using software I have developed, and 495 do not have a timeout problem. Our default is to timeout after 60 minutes, but one particular office times out randomly and without warning. The normal procedure is, like online banking, a pop up comes up to let them know they will be logged out in 60 seconds, or they can click continue to stay logged in.
The timer is based on JS, but on each page load a PHP function checks to see if they are timed out, and if they are, redirect them to the login page. The JS pop up never occurs, so obviously the countdown hasn't happened, but when they click on a link, they are redirected to the login page.
Since the issue only occurs in one office, it leads me to believe it is a firewall or anti-virus issue, but I'm not sure...
Anyone have any thoughts on this?
I'd asked some questions here n answer confirmed stuff n all come to the initial confusion
The problem seems started when I hit "refresh" (when codes changes I usually hit refresh) or there's no activities (means no check whether it's logged or not or do anything in site B)
When it happens, it always prompted to login again...means the check is failing...on the 2nd case it may be caused by timeout setting, but I have no idea on why it's happening by simply refreshing...
Anyone has any idea on what to check in such situation ?
Thanks in advance,
I have a page that you click to from your email to validate your account. Whenever you click that link and it goes to this page, the server connection times out. What is in this code that would make it timeout (it does not give an error, just says connecting...then times out) session_start(); include "../incl/connectdb.php"; $key1 = $_GET['id']; $key2= $_GET['id2']; $query = "select * from users where passkey = '$key1' and pass2 = '$key2' and activation= 'pending' LIMIT 1"; $result = mysql_query ($query) or die (mysql_error()); $row = mysql_fetch_array ($result); if (mysql_num_rows ($result) < 1){ $_SESSION['message'] = "Invalid link"; header ("Location: ../"); exit(); } $query = "update table-name set activation= 'active' where id = '".$row['id']."' "; mysql_query($query); $_SESSION['message'] = "Account validated."; Hi there, I am wondering if you guys can help me make it so my session times out after a previously set time. I have researched this and found no luck. Here is my code.... Code: [Select] <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> Thanks in advance! Dear all, Accoring to I created a soap API for sending SMS but timeout I found the server not reply. so I would like to protect the timeout case like retry or something. $requestmsg = array('msg'=>$msg); /* SEND SOAP API */ $result = $client->SendSMS($requestmsg); /* RESPONSE FROM SOAP API*/
|