khalilov 0 Report post Posted October 1, 2008 If a script runs for too long (30 seconds from what i know),it is automatically stopped. Does this apply to cronjob scripts? cuz my script at some point will handle alot of acounts and info and may exceed 30seconds. I don't want half of my users acounts not be modified =). And if it does, how do you disable it?I also run a script that adds alot of info to my database (about 3000 rows in a table), but it is always stopped at 1600~1800 rows due to the 30 seconds thing. So i have to enter the info by running the script twice, can i disable the 30 seconds thing on a normal script too? Share this post Link to post Share on other sites
toby 0 Report post Posted October 1, 2008 If a cronjob starts a php script, then yes. There is a function to make php last longer, which can be done in php.ini, htaccess or in the php script, http://uk3.php.net/manual/en/function.set-time-limit.php Share this post Link to post Share on other sites
khalilov 0 Report post Posted October 2, 2008 (edited) I 've tried that site but its not working, its giving syntax errors: <?phpset_time_limit ('5');?>Results in:Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Game\lolz2.php on line 2 I've also tried one of their scripts:<?phpset_time_limit(20);while ($i<=10){ echo "i=$i "; sleep(100); $i++;}?>gives:Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Game\lolz2.php on line 2 Iam guessing the set_time_limit(); function isn't working here:/. Note iam trying these on my computer, i have wamp server with Apache Version : 2.2.8 PHP Version : 5.2.6.On a side question i noticed that today i was emailed a message by my cronjob saying,erm do i quote or code it:P?Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/khalilov/cron/tick.php on line 3 mysql_errorMy script was working fine but i moved it to that directory so that no one can enter it manually by just typing the link. And i believe it worked even after i changed the directory for a while. Now its not :/. My scripts runs every 30 minutes btw, why did i recieve this message once O.o. Did the error disable my cronjob? cuz i still see it there.Edit: Now its working O-O, srry if iam contradicting my self or something but it looks like the script gave an error only once, how is that possible/ Edited October 2, 2008 by khalilov (see edit history) Share this post Link to post Share on other sites
ryantommo 0 Report post Posted December 17, 2008 i ad same problem diff site Share this post Link to post Share on other sites
khalilov 0 Report post Posted December 17, 2008 You said had, so did you fix it? if so how? Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 17, 2008 To use this function do this: set_time_limit(0); and the script will run forever, but in fact, I doubt scripts needs to run that kind of time if you program the way you should or unless you're doing something "superb".. You also can change max_execution_time for your script to run with php.ini settings or a .htaccess file by doing:with .htaccessphp_value max_execution_time 120 and it will run for 120 seconds, I guess 0 for forever or maybe -1 who knows, but personally I always set to less than 30 and override the default settings, 10 seconds is usually enough, because if your script is executing so long for no reason then something is usually wrong and the faster it stops the better, for example it's better to run a forever loop for 10 seconds than 30 seconds and save some resources of the server.. isn't it?By the way, all those functions/settings won't work if safe_mode is on. or you don't have access to htaccess files, but if you're on Xisto, you have it.. usually set_time_limit(0) is enough if you REALLY need more execution time. Share this post Link to post Share on other sites
khalilov 0 Report post Posted December 17, 2008 Ah thx, i agree it shouldn't be infinite cuz if something goes wrong my server will lag and needs to be restarted or so. I'll set it to 2 minutes or so. The reason i want to give so much time is that that script might need to modify up to 1000 rows in database tables. As i mentioned I am making a game and each user in the game will have about 30 rows, might increase in the future. So 30 active (hopefully more:P) users=900 +rows. Any cronjob that updates half the players' resources or battles before timing out wouldn't do me good =) Share this post Link to post Share on other sites
toby 0 Report post Posted December 17, 2008 I think it needs to be "set_time_limit('5');", so the '' of one bit and the no space of the other. Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 17, 2008 To tell the truth, on PHP it really doesn't matter if you write set_time_limit(0); or set_time_limit (0); it will still work, also it doesn't matter if you'll give an integer or string as on C or C++, giving ('0') or (0) will work the same, but of course the best practice is to write everything strictly!Why did khalilov get errors like "Parse error: syntax error, unexpected T_STRING in C:\wamp\www\Game\lolz2.php on line 2" I don't know, maybe he used some stupid charset ant those weren't spaces at all, sometimes it happens that when you copy paste some text into your php editor or IDE, you get errors, you remove the spaces or tabs and write your own, the errors are gone.. it's because of different charsets and something like that, the code should work, but as I understand he does everything by copy paste and etc. so thats usually the problem why he has problems. Share this post Link to post Share on other sites
khalilov 0 Report post Posted December 18, 2008 (edited) made a mistake, plz delete Edited December 18, 2008 by khalilov (see edit history) Share this post Link to post Share on other sites