WebFaction
Community site: login faq

Heya all, looking for some help to get my cronjob to work.

For some reason i cant get my cronjob to run a php file i built for it. Ive already tried several things, made sure the php file uses absolute paths, tried a cronjob that points to home/username/.../ aswell as using $HOME like the example below, but neither work, im missing something somewhere, and im clueless what i am actually missing.

This is my cron task (note that i simplified the path to the cron.php file, and im running it every minute for debugging, will run every 15 minutes eventually)

*/01 * * * * /usr/local/bin/php $HOME/webapps/my-web-app/subdir/cron.php

At first the PHP file was just way to fancy, using dependancy injection and whatnot i wasted a day trying to get that to work, but now that i greatly simplified the file, it still wont work :(

It does work flawlessly when i call the file directly from SSH, like so:

/usr/local/bin/php $HOME/webapps/my-web-app/subdir/cron.php

But the actual cronjob either doesnt run, or creates errors with the PHP file that i cant reproduce by running it manually, or find out about in any way (please correct me if im wrong on this)

What the php file does is decide where its running (on what server) by checking getcwd() and based on that it starts a mysqli connection with the proper login details for the related server/database, after that it pulls in 5 records from a database, and then it does two calls for each of those records, one to the Twitter API, and one to the Google Maps API (timezone api actually) and then finally, it saves that back to the database again. Nothing that special right? shouldnt it just work? even more so because it works fine from commandline and even browsing to the file from my computer? And it also works on another (non webfaction) server a-ok.

I already read a load of questions here and on stackexchange trying to find the issue, but i really cant, the only thing i can still try is setting enviornment variables, but im a bit scared to do so, since the crontab also has other cronjobs listed, that may actually be working (idk, they're not mine, sadly its a shared machine/account) and i definatlly dont want to break them.

I should also note that the directory where the cron.php file resides is part of an application that has access too PHP, so i feel like thats not the issue either (though i could be wrong ofc) the application label is "Static/CGI/PHP-5.5" wich to me seems a-ok, i should also note that ive tried to call the php file using "/usr/local/bin/php" aswell as "/usr/local/bin/php55"

Anybody got any life saving ideas?? offcourse this happens half a day before a deadline set in stone, god i hate murphy's law.

Thanks in advance, Olivier

asked 26 Sep '14, 10:37

olivier
314
accept rate: 0%

edited 26 Sep '14, 10:43

Yeeeeessssss! You sir, are a life saver! thanks so much, just, wow.

Making it write the output to a file (wich i shouldve done before hehe) unveiled the crux, the result from getcwd() was different from the actual path of the file the cronjob is calling, because its beeing ran from the user's home dir (wich actually makes total sense now that i think about it some more) so because of that it never even continued to pulling from and writing to the database, because it didnt have any details to setup the mysqli connection with.

Thanks again man, good stuff, your the best.

Convert your comment to awnser so i can give you credit for it :)

(26 Sep '14, 10:58) olivier

Try redirecting the job's output to a file. That usually gives a clue on what the issue is.

To do that change your job to:

/01 * * * /usr/local/bin/php $HOME/webapps/my-web-app/subdir/cron.php >> $HOME/logs/user/cron.log 2>&1

Then update your answer with any results.

permanent link

answered 26 Sep '14, 10:43

iliasr ♦♦
2.1k14
accept rate: 35%

Thanks again, good stuff

(26 Sep '14, 11:21) olivier
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×81
×50
×17

question asked: 26 Sep '14, 10:37

question was seen: 4,629 times

last updated: 26 Sep '14, 11:21

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM