You are here:  » CPU Quota exceeded when running import.php

Support Forum



CPU Quota exceeded when running import.php

Submitted by AD_Mega on Tue, 2007-07-10 07:27 in

I have a cron job to import the modified datafeed each night. Each night I get "CPU Quota exceeded" message when I attempt to goto my website during the import of the datafeeds. My host saythe scrip import,php is using too much cpu time. Is there a way to provent this?

Submitted by support on Tue, 2007-07-10 07:36

Hi,

A couple of users have come across this issue with their hosting provider. It does seem to be resolved by inserting a "wait state" into the import record handler using PHP's sleep() function. To do this, look for the following code on line 289 of includes/admin.php:

    return ($admin_importProductCount == $admin_importLimit);

To insert the wait state, modify the above code as follows (it's actually just inserting a few lines before the above line)

    if (!($admin_importProductCount % 100))
    {
      sleep(1);
    }
    return ($admin_importProductCount == $admin_importLimit);

This will insert a 1 second sleep every 100 products, and should be enough to prevent your cron job from triggering the resource monitor!

Cheers,
David.

Submitted by AD_Mega on Tue, 2007-07-10 16:27

I change the code like you suggested but I'm still getting the exceed cpu quota when I import datafeeds.

Submitted by support on Tue, 2007-07-10 16:36

Hi,

What can happen in this situation is that your host has "marked" the file, and is no longer permitting it to run at all. Can you contact your host and ask if this is the case, and explain that you have modified the file to reduce CPU usage...

It is also worth asking in your email if you can have the CPU limit removed against your account. This is normally in place to prevent runaway scripts from consuming infinite resources. If you explain that the script is designed to import large product feeds and is not "faulty" they may remove the limit on your account. Also mention that you only run the script occasionally and not as part of the everyday operation of your site.

If you're not able to make progress with this, other things to look at are how you are running import. Are you using an automation script, and has this only started to happen after adding more merchants? One option here is to split the script up and only import merchants every few minutes rather than all in one go. On the other hand, if it has just started to happen whereas before there was no problem whilst doing exactly the same thing then again it would be worth making your host aware of this...

It may also be worth increasing the sleep time (e.g go up to sleep(3) or something like that) or reducing the number of records between sleeps...

Hope this helps,
Cheers,
David.

Submitted by AD_Mega on Tue, 2007-07-10 17:39

My host will not remove the limit. I'm running the script to import all modified datafeeds. Most of the time about 5 or 6 feeds are modified a day.I'll increase the sleeptime and see if that helps.

Submitted by AD_Mega on Tue, 2007-07-10 19:01

I must have messes something up when I change the code. I get this error when I try to import feeds manually

Call to undefined function: filter_exec() in /home/megashop/public_html/includes/admin.php on line 159

Submitted by support on Tue, 2007-07-10 19:57

Hi,

This would happen if a filter defined against feed is not in the includes/filter.php file. Check that the filter code has been added to includes/filter.php. If you're not sure about it, please email me your modified files (includes/admin.php and includes/filter.php) and i'll take a look for you...

Cheers,
David.

Submitted by Harvey on Wed, 2007-07-11 10:57

This happened to me - on one occasion I was able to prevent it by double checking the format string/feed type on register - it autodetected it incorrectly.

Alternatively it may be time to upgrade...

Submitted by scorpionwsm on Wed, 2007-07-11 11:49

Depending upon which host you are with depends on the quality of this script being honest.

I was on 1&1 business pro hosting before I got this script which was fine for my needs, but knowing that this script has some potential or hopefully it does, I upgraded to dedicated server level 1.

I now have 100 unlimited I think MYSQL databases and am whacking this script up as fast as I can on various domains.

I haven't had a problem since being on a dedicated server and I'm glad that I upgraded being honest as takes a lot of the hassle away as I was ending up putting two or three websites onto the same database which was getting confusing.

The script is not 100% perfect but with dedicated servers, a few mods bolted on a customed designed website, then most people would be onto a winner.

David is a fantastic guy from my dealings with him, the mods work and are excellent, and increase the potential of the script.

In business you only get out what you put in, I have over stretched myself financally now but I am expecting double the returns in the future maybe even more.

Hopefully I have stopped buying domain names now as I seem to have every categeory that I could wish for, I even brought a domain for magazines and books yesterday, god knows why as the money is rubbish on it, but why the hell not :)

Regards

Mark

Submitted by scorpionwsm on Wed, 2007-07-18 00:12

Hi David,

Think you must have been either very tired, drunk or both when you wrote this one lol

Do you replace this line return ($admin_importProductCount == $admin_importLimit);

For this if (!($admin_importProductCount % 100))
{
sleep(1);
}
return ($admin_importProductCount == $admin_importLimit);

Or do you insert the sleep lines, before the return ($admin_importProductCount == $admin_importLimit);

Not sure if it's because I'm using an old router, but since I haven't been able to use my wireless router the past couple of days, things seemed to have slowed down for some reason.

Regards

Mark

Submitted by support on Wed, 2007-07-18 07:00

Hi Mark,

It's tricky to indicate where to include modifications like this! In this case, look for the line shown, and then modify that area of code as indicated. The modification includes the original line....

In this case it wouldn't make any difference because once a return statement is reached the function returns, and since the modification includes the very same return line it would all still work.

Cheers,
David.