Solved

Cron fopen error

Posted on 2008-06-19
7
622 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to count occurrences of each item in an array.

770 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