4

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.

Community
  • 1
  • 1
  • Well, at first, don't worry about permissions, it would trigger another error. – SpongePablo May 28 '15 at 14:12
  • 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 May 28 '15 at 14:13
  • require_once() might fail because of another current working directory. Check it in runtime. – Sergei Kovalenko May 28 '15 at 14:13
  • 1
    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 May 28 '15 at 14:15
  • 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 May 28 '15 at 14:17
  • Yes, fvu, the file exists. I'll try your suggestion. – Daan van den Bergh May 28 '15 at 14:18
  • --2015-05-28 16:20:01-- https://www.filmhuisalkmaar.nl/wp-content/themes/filmhuis-alkmaar/cron/load-shows.php Resolving www.filmhuisalkmaar.nl... 91.221.150.193 Connecting to www.filmhuisalkmaar.nl|91.221.150.193|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10 [text/html] Saving to: “/dev/null” 0K 100% 781K=0s 2015-05-28 16:20:07 (781 KB/s) - “/dev/null” saved [10/10] That was the result! So, I guess that's good! :D – Daan van den Bergh May 28 '15 at 14:22
  • cron jobs start up in the user's home directory, no matter where the script actually resides. if you're using relative paths, then they'll be relative to the home directory, not the script's location. – Marc B May 28 '15 at 14:27
  • @DaanvandenBergh as `/dev/null` is the bottomless bit garbage can your output is obviously thrown away, feel free to redirect it to some file in /tmp or whereever if that suits your needs better :) – fvu May 28 '15 at 14:32
  • Yes, I changed the command to 'wget -o -' and appended '>> log.txt' at the end, just to see if the scripts are executed correctly. So far, so good. :) Thanks a lot, fvu e.a. :) – Daan van den Bergh May 28 '15 at 14:41

3 Answers3

0

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".

Michal Przybylowicz
  • 1,558
  • 3
  • 16
  • 22
0

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. : )

Joel F.
  • 59
  • 8
  • That is actually a very useful answer. I didn't write the script so I wasn't aware of this, but this is actually really useful. I know I can use this in the future. Thanks! – Daan van den Bergh May 29 '15 at 23:32
0

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!