steviez Posted June 24, 2008 Share Posted June 24, 2008 Hi, My host has just susspended my account for overloading the cpu with my script, the only active PHP code i have at the moment is a random array that returns a image randomly on the front page. Can you please have a look and tell me if it would be causing the overload? Code: <?php // Throw out a random image $pic = array("front_pic_1.jpg"=>"Front_Pic_1","front_pic_2.jpg"=>"Front_Pic_2","front_pic_3.jpg"=>"Front_Pic_3","front_pic_4.jpg"=>"Front_Pic_4","front_pic_5.jpg"=>"Front_Pic_5"); print_r(array_rand($pic,1)); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/111712-help-with-script/ Share on other sites More sharing options...
hitman6003 Posted June 25, 2008 Share Posted June 25, 2008 pretty sure that unless that "script" is being called many thousands of times per second, it's not causing a problem. On my Core 2 Duo Laptop running Fedora 8, I ran the your code above one million times in 14.01 seconds, during that time, it consumed 48% CPU...or about 96% of one core. At that rate, your code would have to be called 71428 times per second to consume 100% of CPU resources. I think that either the problem lies somewhere else, or you need a new host who doesn't whine when you use more than 2% cpu. <?php $iterations = 1000000; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { // Throw out a random image $pic = array( "front_pic_1.jpg"=>"Front_Pic_1", "front_pic_2.jpg"=>"Front_Pic_2", "front_pic_3.jpg"=>"Front_Pic_3", "front_pic_4.jpg"=>"Front_Pic_4", "front_pic_5.jpg"=>"Front_Pic_5" ); print_r(array_rand($pic,1)); } echo "\n\nTotal time for " . $iterations . " iterations: " . (microtime(true) - $start) . " seconds"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/111712-help-with-script/#findComment-573768 Share on other sites More sharing options...
.josh Posted June 25, 2008 Share Posted June 25, 2008 Yeah there's no way that script in and of itself could be the problem. I think you should ask them to be more specific. It's possibly someone(s) could be targeting your script with a bot, requesting it over and over, or some other kind of DNS attack. Quote Link to comment https://forums.phpfreaks.com/topic/111712-help-with-script/#findComment-573790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.