1

I created a product import script for Magento around a year ago and it's been running successfully since then, downloading several XML files containing the product catalogue, stock quantities and discontinued product list, as well as the images files associated with each product.

Suddenly this week the script no longer runs to completion. It appears to just end abruptly but with no error message being shown either on screen or on the server's error.log file in the directory containing the script.

I have the following at the head of my script so I ought to be seeing errors if they are actually occurring:

error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 'On');

The only thing I've seen that might be related, but I'm not convinced because I don't see it at all when I run the script from my browser - it only occurs if the script is run from crontab (php .../public_html/import/ss365products.php >/dev/null 2>&1), is the following in the error.log file:

[26-Sep-2012 12:00:01] PHP Warning:  require_once(/app/Mage.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in .../public_html/import/TempProducts.php on line 5

I'm not really sure why I'm getting that at all being that Mage.php hasn't gone anywhere!

So... I'm really not sure where to look now to debug this issue. Any advice greatly recieved!

2
  • Couple questions i have: - which Magento version you're using ? - do you use cache system ? - how often you get this error ? Commented Sep 26, 2012 at 19:40
  • Magento v1.5.1. Caching is by way of APC. Error occurs every time the cron job runs but NEVER when I run the script from a browser... Commented Sep 26, 2012 at 20:10

4 Answers 4

1

For the cron, just give full folder path to Mage.php and your script will run just fine. When running over apache, the /app is relative to the webroot folder, but while running as cron it will try to find the folder relative to the filesystem.

Sign up to request clarification or add additional context in comments.

5 Comments

The file that includes Mage.php (tempproducts.php) is itself included into my productimport script (ss365products.php) using the following: require_once($_SERVER['DOCUMENT_ROOT']."/app/Mage.php");
When running as cron from command line, you do not have DOCUMENT_ROOT within the PHP script, since there is no web server rendering your page.. (unless you are running the script using lynx or something, which I think is unlikely)
Ok - this I did not realise! I've now hardcoded the root folder in place of any dynamic document_root in the relevant files. Thank you. That ought to rectify the one error message I'm seeing in the error.log file when the script is running via crontab BUT it still won't fix the fact that the script is aborting midway through execution when I've been running it in a browser. How can I start to debug what's happening there?
I've also realised why the cron job wasn't showing that error until recently - I was advised to use command line PHP to run the script instead of, I think it was cURL? It would have been at that point that the error.log entries started. My guess at the cause of the other problem is perhaps a change to the format of one of the XML files or a memory allocation problem or similar...
Ok, so when you run as cron also remember that you do not get error written into error_log, since the error log belongs to apache and you will see it only if running through browser (or some variant like using curl or lynx or something). You can use the redirection command to write all error or stdout into a text file and check what is going on..
0
[26-Sep-2012 12:00:01] PHP Warning:  require_once(/app/Mage.php)

That doesn't look like a relative path. Maybe it's looking for Mage.php at the root directory?

Try this: require_once "/full/path/to/app/Mage.php"

1 Comment

The file that includes Mage.php (tempproducts.php) is itself included into my productimport script (ss365products.php) using the following: require_once($_SERVER['DOCUMENT_ROOT']."/app/Mage.php");
0

use require_once(__DIR__ . '/app/Mage.php');

1 Comment

The file that includes Mage.php (tempproducts.php) is itself included into my productimport script (ss365products.php) using the following: require_once($_SERVER['DOCUMENT_ROOT']."/app/Mage.php");
0

In command line there is no $_SERVER['DOCUMENT_ROOT'], so it will search Mage.php in the wrong path. The script can abort because of some php.ini settings which possibly are not applied (i.e. a time limit is set).

Maybe you should access the cron job as a webpage using:

wget http://yourdomain/cron.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.