4
votes

Recently my site was moved to a different server, due to maintenance at the host. Ever since I can't this script to run as a cronjob anymore: http://www.filmhuisalkmaar.nl/wp-content/themes/filmhuis-alkmaar/cron/load-shows.php

I tried running it using PHP with the follow cronjob:

php /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/cron/load-productions.php

But I kept getting the following error:

PHP Warning: require_once(../inc/api.php): failed to open stream: No such file or directory in /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/cron/load-productions.php on line 3 PHP Fatal error: require_once(): Failed opening required '../inc/api.php' (include_path='.:/usr/local/lib/php') in /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/cron/load-productions.php on line 3

I checked if the files stating missing were still in place. And they were. I checked the file permissions and they're set to 755, which should be more than fine. Right?

Then I tried wget with the following cronjob:

/usr/bin/wget -O https://www.filmhuisalkmaar.nl/wp-content/themes/filmhuis-alkmaar/cron/load-shows.php

But then I keep getting the following URL:

wget: missing URL

Usage: wget [OPTION]... [URL]...

Try ‘wget --help’ for more options.

I'm really at a loss here. Especially because it used to work fine in the past. It's very frustrating because these scripts are kind of essential for my site to stay updated.

Any help would really be appreciated. Thank you.

3
Well, at first, don't worry about permissions, it would trigger another error. - SpongePablo
Failed opening required '../inc/api.php' (include_path='.:/usr/local/lib/php') : this means that the file is being searched in /usr/local/lob/php/../inc/api.php which means /usr/local/lob/inc/api.php is the file in that path? - SpongePablo
require_once() might fail because of another current working directory. Check it in runtime. - Sergei Kovalenko
1) does /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/inc/api.php exist? 2) obvious error in wget usage (-O needs the name of the file in which to save the script output), try wget -O /dev/null https://www.filmhuisalkmaar.nl/wp-content/themes/filmhuis-alkmaar/cron/load-shows.php ` - fvu
SpongePablo: the path to the api.php is "/home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/inc/api.php". Since the script is located in "/home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhuis-alkmaar/cron/" the "../" should go up one folder and follow the path, right? It used to before. I tried setting the complete path as well. Giving the same error. - Daan van den Bergh

3 Answers

0
votes

Try to run it like this:

cd /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhui‌​s-alkmaar/cron/ && php load-productions.php

Note the use of cd command at start. This means "change current working directory to ../cron/ and then run script load-productions.php".

0
votes

I prefer for cron tasks to use the use the full path to included and required scripts. So, instead of:

require_once("../inc/api.php");

I generally do:

$base = dirname(dirname(__FILE__));
require_once($base . "/inc/api.php");

This way the server knows exactly where to look and is not relative to certain directories.

Side note: I also like to do /path/to/php -q /path/to/script.php too. : )

0
votes

I will quote fvu's comment to my question, which I have tried and can confirm now as fully working:

1) does /home/provadja/domains/filmhuisalkmaar.nl/public_html/wp-content/themes/filmhui‌​s-alkmaar/inc/api.php exist? 2) obvious error in wget usage (-O needs the name of the file in which to save the script output), try wget -O /dev/null https://www.filmhuisalkmaar.nl/wp-content/themes/filmhuis->alkmaar/cron/load-show‌​s.php

Thanks a lot everyone, for your help!