Solved

Cron fopen error

Posted on 2008-06-19
7
619 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can windows 10 wamp send mail()? 3 34
mysqli 3 21
using php variable inside javascript 5 14
Setting up static IP - Ubuntu server 16.04 12 31
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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

920 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

13 Experts available now in Live!

Get 1:1 Help Now