Link to home
Start Free TrialLog in
Avatar of phper
phper

asked on

Cron fopen error

I made a cron job that works fine when I manually run it but when it runs as a cron I get the following error. The all the scripts included in the cron start with: chdir(dirname(__FILE__));
PHP Warning:  fopen(files/writetofile.txt): failed to open stream: No such file or directory in /var/www/html/domain/dev/class.pdf.php on line 112
PHP Stack trace:
PHP   1. {main}() /var/www/html/domain/dev/index.php:0
PHP   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
PHP   3. fopen() /var/www/html/domain/dev/class.pdf.php:112
 
Warning: fopen(files/writetofile.txt): failed to open stream: No such file or directory in /var/www/html/domain/dev/class.pdf.php on line 112
 
Call Stack:
    0.0003      70576   1. {main}() /var/www/html/domain/dev/index.php:0
  150.1073    1118656   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
  150.1171    1948600   3. fopen() /var/www/html/domain/dev/class.pdf.php:112
 
PHP Warning:  fwrite(): supplied argument is not a valid stream resource in /var/www/html/domain/dev/class.pdf.php on line 113
PHP Stack trace:
PHP   1. {main}() /var/www/html/domain/dev/index.php:0
PHP   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
PHP   3. fwrite() /var/www/html/domain/dev/class.pdf.php:113
 
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/html/domain/dev/class.pdf.php on line 113
 
Call Stack:
    0.0003      70576   1. {main}() /var/www/html/domain/dev/index.php:0
  150.1073    1118656   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
  150.1172    1949368   3. fwrite() /var/www/html/domain/dev/class.pdf.php:113
 
PHP Warning:  fclose(): supplied argument is not a valid stream resource in /var/www/html/domain/dev/class.pdf.php on line 114
PHP Stack trace:
PHP   1. {main}() /var/www/html/domain/dev/index.php:0
PHP   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
PHP   3. fclose() /var/www/html/domain/dev/class.pdf.php:114
 
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/html/domain/dev/class.pdf.php on line 114
 
Call Stack:
    0.0003      70576   1. {main}() /var/www/html/domain/dev/index.php:0
  150.1073    1118656   2. fapdf->make_pdf_csv() /var/www/html/domain/dev/index.php:20
  150.1173    1949368   3. fclose() /var/www/html/domain/dev/class.pdf.php:114

Open in new window

Avatar of Roonaan
Roonaan
Flag of Netherlands image

Does it make a difference if you add the next line to the top of your script?
chdir(dirname(__FILE__))
Avatar of phper
phper

ASKER

Yes, in the past this cron was on a different server and if I didn't have that line as the next line to the top it would look for the file writetofile.txt in the site's root folder. Which kind of looks like what's happening here, but I have chdir(dirname(__FILE__)) in there
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phper

ASKER

Roonaan: I don't know. I set it up in webmin. Maybe it's running as apache. How can I check?
hernst42: Yes,  /var/www/html/domain/dev/files exists and is writable
Avatar of phper

ASKER

hernst42: Also, remember when I run the page manually it works fine. So, /var/www/html/domain/dev/files exists and is writable
which permissions does the file /var/www/html/domain/dev/files/writetofile.txt have?