Solved

Cron fopen error

Posted on 2008-06-19
7
625 Views
Last Modified: 2010-08-05
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
Comment
Question by:phper
  • 3
  • 2
  • 2
7 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 21824767
Does it make a difference if you add the next line to the top of your script?
chdir(dirname(__FILE__))
0
 

Author Comment

by:phper
ID: 21824796
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
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 21824982
As which user is php running when ran from cron?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 250 total points
ID: 21825080
does the directory  /var/www/html/domain/dev/files exists and is writeable by the cron user?
0
 

Author Comment

by:phper
ID: 21829393
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
 

Author Comment

by:phper
ID: 21829397
hernst42: Also, remember when I run the page manually it works fine. So, /var/www/html/domain/dev/files exists and is writable
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21829470
which permissions does the file /var/www/html/domain/dev/files/writetofile.txt have?
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fine Tune your automatic Updates for Ubuntu / Debian
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question