Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler_cron.sh via cron causes Warning: strpos(): Empty needle in Http.php on line 508 and 514 #233

Open
minc21 opened this issue Feb 4, 2016 · 10 comments

Comments

@minc21
Copy link

minc21 commented Feb 4, 2016

Hello,

when I run the scheduler_cron.sh direct in bash it runs smooths. But when I run it via crontab I get warnings in system.log:

2016-02-03T13:45:02+00:00 ERR (3): Warning: strpos(): Empty needle in /home/xxx/shop/lib/Zend/Controller/Request/Http.php on line 508
2016-02-03T13:45:02+00:00 ERR (3): Warning: strpos(): Empty needle in /home/xxx/shop/lib/Zend/Controller/Request/Http.php on line 514

seems to be something like this:
http://stackoverflow.com/questions/9128488/cron-job-server-issue

#212

@minc21
Copy link
Author

minc21 commented Feb 7, 2016

update:

changes in scheduler_cron.sh seems to fix it:

from:
PHP_BIN=$(which php || true)
to:
PHP_BIN=$(which php-cli || true)

also 5cc0cb4 isn't necessary any more!

@sreichel
Copy link
Contributor

Can this be included?

@MMB1983
Copy link

MMB1983 commented Aug 3, 2017

After trying every possible solution I found online (including this above) I still have this warning. I run Magento CE 1.9.1 with all latest patches :-(
Warning: strpos(): Empty needle in ../lib/Zend/Controller/Request/Http.php on line 508
Warning: strpos(): Empty needle in ../lib/Zend/Controller/Request/Http.php on line 514
My cron job is: sh /full_path/cron.sh

@LeeSaferite
Copy link
Contributor

Just to add a little clarity here. The warning you are seeing is triggered when the Zend_Controller_Request_Http class tries to call setBaseUrl(null) when in CLI mode. In vanilla Magento, this only ever seems to happen when you call getBaseUrl() on the class. Without spending a lot of time going through all the core code and all the scheduler code, my guess is that one of the cron jobs you are running is attempting to use a request object when it shouldn't. To help track this down you could look into adding additional logging around the warning handler and perhaps generate a full stack trace.

If you have a proper xdebug setup, you can add a conditional breakpoint to the two location generating the warning. The conditional would be empty($baseUrl) and should stop program execution in the situation that would generate the warning.

If you get desperate you could edit the lib/Zend/Controller/Request/Http.php file and add a log of the debug backtrace. Something like if(empty($baseUrl)){ error_log(print_r(debug_backtrace(), true)); }

Keep in mind, you should never edit core files. The above suggestion is really just for a debugging situation on a testing server or local install.

@MMB1983
Copy link

MMB1983 commented Aug 3, 2017

Thanks for reply. Both errors appear every 5 minutes when cron runs cron.sh when I switch to cron.php it is OK. This is my exact cron command: sh /home/vp/public_html/my_domain/cron.sh >/dev/null 2>&1 it is running every 5 minutes.

@LiamMcArthur
Copy link

LiamMcArthur commented Sep 12, 2017

@minc21 making the change in scheduler_cron.sh didn't fix the issue for me, but implementing the change in cron.sh did! 👍

@MMB1983
Copy link

MMB1983 commented Sep 12, 2017

Hi Liam if I may ask you, what changes did you made ?

@LiamMcArthur
Copy link

LiamMcArthur commented Sep 13, 2017

I changed line 39 in cron.sh at the root of the Magento installation from:

PHP_BIN=which php

to:

PHP_BIN=which php-cli

@MMB1983
Copy link

MMB1983 commented Sep 18, 2017

Hi Liam,
here is the update:
When I changed 14th line from PHP_BIN=which php to PHP_BIN=which php-cli my cron job stopped working with no error messages. Jobs were marked as pending. Obviously the warning with empty needle disappeared but the cron wasn't working (one doesn't go without another)
I applied the same change to scheduler_cron.sh but no luck either.
Regards

This is my unchanged cron.sh

#!/bin/sh
#location of the php binary
if [ ! "$1" = "" ] ; then
CRONSCRIPT=$1
else
CRONSCRIPT=cron.php
fi

MODE=""
if [ ! "$2" = "" ] ; then
MODE=" $2"
fi

PHP_BIN=which php

#absolute path to magento installation
INSTALLDIR=echo $0 | sed 's/cron\.sh//g'

#prepend the intallation path if not given an absolute path
if [ "$INSTALLDIR" != "" -a "expr index $CRONSCRIPT /" != "1" ];then
if ! ps auxwww | grep "$INSTALLDIR$CRONSCRIPT$MODE" | grep -v grep 1>/dev/null 2>/dev/null ; then
$PHP_BIN $INSTALLDIR$CRONSCRIPT$MODE &
fi
else
if ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
$PHP_BIN $CRONSCRIPT$MODE &
fi
fi

@ddoddsr
Copy link

ddoddsr commented Sep 18, 2017

M/k1983,
Liam's line PHP_BIN=which php-cli
might need to be something else...
Check with your hosting company for the name of the php-cli
which is php compiled for the command line.
The php-cli might be compiled with litespeed in mind and named differently.
There might be other reasons it dosen't exist under that name in you path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants