?
Solved

Cron fopen error

Posted on 2008-06-19
7
Medium Priority
?
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 total points
ID: 21824982
As which user is php running when ran from cron?
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 750 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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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