I'm having a hard time finding out what is causing these errors, but they only started once I was able to get my CronJobs working, so I believe they are tied to that. I am calling the Magento Crons by Cpanel command:

*/5 * * * * /usr/php/54/usr/bin/php /MyServerInfo/public_html/cron.php >/dev/null &2>1

(I wanted to call Cron using cron.sh but was unable to get that to work, if interested in that struggle see post: Cronjobs Magento - Is it possible to have Cron.sh call Cron.php by /usr/php/54/usr/bin/php)

I am getting these in my system.log file every 5 minutes, which matches the CronJob timeline:

2016-01-14T01:55:01+00:00 ERR (3): Warning: strpos(): Empty needle  in /MyServerInfo/public_html/lib/Zend/Controller/Request/Http.php on line 508
2016-01-14T01:55:01+00:00 ERR (3): Warning: strpos(): Empty needle  in /MyServerInfo/public_html/lib/Zend/Controller/Request/Http.php on line 514

And this in my error_log every 5 minutes as well:

[13-Jan-2016 23:40:01 UTC] PHP Notice:  Undefined index: SCRIPT_NAME in /MyServerInfo/public_html/cron.php on line 41
[14-Jan-2016 18:55:02 UTC] PHP Notice:  Undefined index: SCRIPT_NAME in /MyServerInfo/public_html/cron.php on line 40

I have been doing research and the best I have been able to find is a "temporary solution" that involves altering the Core files, which I would prefer not to do. I would rather fix the underlying problem if possible: See a temporary solution to this problem:

Edit file: lib/Zend/Controller/Request/Http.php

Line 504: if (0 === strpos($requestUri, $baseUrl)) {

Replace with:

if (!empty($baseUrl) && 0 === strpos($requestUri, $baseUrl)) {

Line 510:

if (0 === strpos($requestUri, dirname($baseUrl))) {

Replace with:

if (!empty($baseUrl) && 0 === strpos($requestUri, dirname($baseUrl))) {

I also found this related post: Cron.php undefined index 'SCRIPT_FILENAME'

But it seems like they are talking about doing something with command line access, which I do not have. Only Cpanel.

Any help or direction would be appreciated.

  • It seems that the way you run Magento it is behaving like it is responding to a user request and not running a shell script. Sorry that I'm not of more help
    – Michael
    Jan 14, 2016 at 3:30
  • Did you perhaps override php.ini, in your attempt for solve the PHP issue in the other question, for CLI so that Magento cannot see that it runs from command line?
    – Michael
    Jan 14, 2016 at 3:35
  • @Michael the only thing I did with php.ini was change the timezone. It is possible that the hosting company changed it when trying to help me with the php environment one of the times I was speaking with them, probably not.
    – Classic
    Jan 14, 2016 at 5:36
  • The error_log errors are coming from these two lines of code in cron.php: // Only for urls // Don't remove this $_SERVER['SCRIPT_NAME'] = str_replace(basename(FILE), './index.php', $_SERVER['SCRIPT_NAME']); $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(FILE), './index.php', $_SERVER['SCRIPT_FILENAME']);
    – Classic
    Jan 22, 2016 at 23:18

1 Answer 1


For me at least, both the EMPTY NEEDLE issue and the SCRIPT_FILENAME issue, seems to be resolved. Turns out the answer was linked in my original post for this problem, but either it was updated when I went back to research it again, or I didn't get it the first time. If you go in to your Cron Jobs at your Host or wherever you are originally calling them from, and just change the PHP to PHP-CLI it fixes the issue. For example in my case I just changed /usr/php/54/usr/bin/php /YourHostInfo/public_html/cron.php >/dev/null 2>&1 to /usr/php/54/usr/bin/php-cli /YourHostInfo/public_html/cron.php >/dev/null 2>&1

My Cron Jobs are still running and no more Script_Filename or Empty Needle errors.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.