1

I need to run a php script to generate snapshots using CutyCapt of some websites using crone job, i get websites' addressess from database and then delete this record after generating screenshots. i used */5 * * * * /usr/bin/php -f /path/generate.php it didn't worked for crone job but if i access the same file using browser it works fine, and if run this script using command php from command line it also works fine. then i just created another file and accessed the url using file_get_contents; added this file to crone job it worked fine for some days but now this approach is also not working. i don't know what happened. i didn't change any of these files. I also tried wget command to access that url but failed to get required out put. my crontab is now looks like this */5 * * * * wget "http://www.mysite.com/generate.php" -O /dev/null

Strange thing is that crone job executes fine it fetches data from database and deletes record as well but does not update images.

Is there any problem with rights or something similar that prevents it to generate images using crone job but not when accessed using browser.

Please help i am stuck.

Arif
  • 1,601
  • 2
  • 21
  • 34

2 Answers2

0

I don't know what your script is doing internally, but keep in mind that a user's cron jobs do not inherit the users environment. So, you may be running into a PATH issue if your php script is running any shell commands.

If you are running shell commands from the script, try setting the PATH environment variable from within your php script and see if that helps.

Erik
  • 176
  • 1
  • 4
0

is there any user credintials on this page , such as Basic authentication ? if so , you have to define the user name and password in wget request like

wget  --http-user=user --http-password=password "http://url" ?

and try another solution by running yor script from php command line so your crontab could look like

*/5 * * * * /usr/bin/php -f /path/to/generate.php 

try this solution it will work and it is better than hitting the server to execute background operations on your data

and I hope this helps

Muhannad A.Alhariri
  • 3,702
  • 4
  • 30
  • 46
  • 1
    Yeah, the `wget` solution should work. Not all scripts run properly in CLI mode. – Nadh Apr 26 '12 at 17:33
  • I agree with you , but from design perspective I suggest to run from command line! :) – Muhannad A.Alhariri Apr 26 '12 at 17:38
  • @Muhannad thanks for your answer. firstly, there is no authentication required to access this file. secondly, i have tried second solution you suggested, i mentioned in question also. Cron job executes but does not generates screen shots other work related to database update works good. – Arif Apr 26 '12 at 17:58