doc1355 Posted February 24, 2009 Share Posted February 24, 2009 Hi: I have a php script that gathers some information from different tables in one database then add them in a specific way to another table. The problem with my script is that running this script on my shared hosting exceeds the CPU limit of 60%. I received a message from my hosting company that my process is using move than 75% of processor. So, they have an automated system that kills my script. Unfortunately I cannot change the max_execution_time on the server, because it is shared. Now, what I'm looking for is that if there is a script that I can add to my php script that limits the processor usage by certain percent (for example 40%) then it sleeps every 25 seconds and resume again after 10 seconds. I know about the sleep command but I don't know how to use it in my script for this purpose. Here is the script that I'm running: <?php set_time_limit(0); $mageFilename = 'app/Mage.php'; require_once $mageFilename; umask(0); // clean overall cache Mage::app()->cleanCache(); echo "Cache Cleaned!<br/>\n"; Mage::getSingleton('catalogindex/indexer')->plainReindex(); echo 'Layered Navigation Indices was refreshed succesfuly<br>'; ?> Thank you. Quote Link to comment Share on other sites More sharing options...
trq Posted February 25, 2009 Share Posted February 25, 2009 Now, what I'm looking for is that if there is a script that I can add to my php script that limits the processor usage by certain percent (for example 40%) then it sleeps every 25 seconds and resume again after 10 seconds. I know about the sleep command but I don't know how to use it in my script for this purpose. There is no realistic way of doing this through php and apache. sleep itself uses cpu while your script would need to sit within a loop. I have a php script that gathers some information from different tables in one database then add them in a specific way to another table. Seems you may be better off executing this script via the cli and cron. Quote Link to comment Share on other sites More sharing options...
npsari Posted February 25, 2009 Share Posted February 25, 2009 I used too much CPU aswell That is what my hosting company told me So, they suddenly shut my site down I was kinda angry They said because you are on a shared Server So, i then got my Dedicated server Perhaps this is what you should do if your CPU is always high Or check your scripts, perhaps something is causing Apache to get confused Quote Link to comment Share on other sites More sharing options...
doc1355 Posted February 25, 2009 Author Share Posted February 25, 2009 Seems you may be better off executing this script via the cli and cron. Even running via cron is killing my script. ... So, i then got my Dedicated server Perhaps this is what you should do if your CPU is always high Will, I was thinking about upgrading to VPS, but this exec time is the only limit that I have with my shared server and I just want to run this file once every few days. I don't really want to spend twice as I'm spending on my hosting fee only for one small problem. That's why I'm looking for a solution. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 25, 2009 Share Posted February 25, 2009 that isn't the point of sleep. You need to build this better and insert off your select query or not do what your doing because it sounds like poor programing Quote Link to comment Share on other sites More sharing options...
npsari Posted February 25, 2009 Share Posted February 25, 2009 Ohh, i understand what you mean, you dont want to pay extra for running a script for few days Actually, you are correct If i was in your case, i will move to a new hosting company (With the same Shared hosting plan) And hope that they will not mention anything about the CPU usage Hopefully their servers are much faster and wont cause no problems Quote Link to comment 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.