Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

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

0
phper
Asked:
phper
  • 3
  • 2
  • 2
2 Solutions
 
RoonaanCommented:
Does it make a difference if you add the next line to the top of your script?
chdir(dirname(__FILE__))
0
 
phperAuthor Commented:
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
0
 
RoonaanCommented:
As which user is php running when ran from cron?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hernst42Commented:
does the directory  /var/www/html/domain/dev/files exists and is writeable by the cron user?
0
 
phperAuthor Commented:
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
0
 
phperAuthor Commented:
hernst42: Also, remember when I run the page manually it works fine. So, /var/www/html/domain/dev/files exists and is writable
0
 
hernst42Commented:
which permissions does the file /var/www/html/domain/dev/files/writetofile.txt have?
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now