mouldy_punk
06-03-2005, 05:52 PM
If I made a script, say:
<?PHP
$var = 'spin me right round baby right round';
while($var == 'spin me right round baby right round'){
echo $var;
$var = $var;
}
?>
It would just keep looping round and round in circles. Would that mess up the server? I would try it to find out, but my host probably wouldn't be happy if I crashed their server, and I haven't got around to installing apache and stuff on my PC since I reformatted yesterday.
Koobi
06-03-2005, 06:50 PM
This should answer your question:
http://www.php.net/manual/en/ref.info.php#ini.max-execution-time
Your script will terminate after it has run for the max_execution_time.
You will probably see some form of error notice on the web page, rather than the server crashing. No self-respecting scripting language would allow the server to crash based on user input :)
dandans
06-03-2005, 10:39 PM
Your server can handle this. The only result is the thread responsible for this request will time out. Other threads won't be affected.
Burhan
06-04-2005, 01:59 AM
A simple infinite loop is :
<?php
while(1) { echo 'Whee!!<br />'; }
?>
And yes, your server can handle this because your php script will time out after the set time limit is reached.
innova
06-06-2005, 12:22 AM
It all depends on what your 'infinite' loop does. If all it does is echo static strings, its not a problem.
If however it processes a ton of files, using preg_replace, making database connections, or otherwise generating a lot of CPU or I/O intensive activities, yes it will be a problem :)
To make your loop infinite you need to make the timeout '0'.
Marble
06-06-2005, 12:35 AM
Isn't there a maximum amount of memory php can use?
Koobi
06-06-2005, 04:17 AM
memory_limit (http://www.php.net/manual/en/ini.core.php#ini.memory-limit) is a directive in php.ini that does this.
There are also other directives which limit memory allocated for _POST data, uploaded files, etc...but they are all on that same page I linked you to :)
mouldy_punk
06-06-2005, 05:06 AM
Ok, thanks for all the replies =) I figured it would be a bit stupid for PHP to let a script crash the server as easily as that.
error404
06-06-2005, 06:17 AM
It should certainly never crash the server. Even if you were to saturate the CPU doing as much as possible inside your infinte loop, the web server and OS would handle it just fine, though a little slower.
But yes, if you're running something like that and you don't have your own server to abuse, your host is going to complain.