endless loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

endless loop

Post by ddragas »

Hi all

I'm having site that sends and receives sms messages. sms-es are beeing sent and recived in my system trough SMPP protocol that works in loop "listening" for new messages.

How can I make endless loop regarding time of execution?

should I do something with

ini_set("max_execution_time",$time_of_execution);


All suggestions are welcome

kind regards
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post by mrkite »

Code: Select all

set_time_limit(0);
That will disable the time limit on a script. Although I think by default, php-cli doesn't have a max execution time.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

sleep() should also be used.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

of course

thank you both for reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

it has passed some time from my last post in this topic, but there are some new dilemmas on this issue

I've made some changes in my script using time loop

Code: Select all

set_time_limit(0); 

do{
		if ($connected == 0)
		{
			$smpp->Receive();
			sleep(10);
		}

	}while(time() < (time() + 31536000));
but after few minutes script cracks and I get Internal Server Error

what I need is endless loop that will not brake.

all suggestions are welcome

thank you in advance

Kind regards
ddragas
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

exactly loop breaks after 12 - 13 minutes.

does somebody know why?

I'm testing this local on desktop computer (WinXP + apache 2 + mysql5 + 5.027 + PHP5)

please - all suggestions are welcome
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Do you run PHP in safe mode?

From the PHP manual:
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.
...
Warning:
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Do you run PHP in safe mode?

From the PHP manual:
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.
...
Warning:
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you for both replys :D but safe_mode = Off
willearp
Forum Newbie
Posts: 3
Joined: Wed Nov 07, 2007 3:48 am

Endless Loop

Post by willearp »

Why not set a Cron on the server that calls your script, say every 30 seconds? Just be sure to limit how much work the script does each time so it has an end point

Will Earp
Post Reply