Solved

Cron fopen error

Posted on 2008-06-19
7
616 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now