Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

fopen --  failed to open stream: No such file or directory

Posted on 2011-09-28
16
Medium Priority
?
1,098 Views
Last Modified: 2012-05-12

Hello

I'm trying to set up a cron job, but I barely know what I'm doing.  Below are the details of what I've done and the error I'm getting.

------------------------------------------------

Set up simple cron job in cPanel to go off every minute ( just while I'm trying to figure things out)
command: php /home/user_name123/public_html/cron.php

If I go to www.mysite.com/cron.php I get the following Error
Warning: fopen([http://mysite.com/?ACT=40]) [function.fopen]: failed to open stream: No such file or directory in /home/user_name/public_html/cron.php on line 2

I added my email address to "Send an email every time a cron job runs. " option, so I know the cron is working. The email shows the same error as what's rendered in the browser window



Thanks for any help or insights!
Jules

In my cron.php I have:
<?php 
fopen('[http://mysite.com/?ACT=40]','r');
?>

Open in new window

0
Comment
Question by:Jules Webb
[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
  • 8
  • 4
  • 3
  • +1
16 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36715017
Check to see if you host has allowed fopen in your php.ini config file. Ask them to add the line:
allow_url_fopen = On
0
 
LVL 2

Author Comment

by:Jules Webb
ID: 36715476
Hi sonawanekiran

I have two instances of this going on.  On one site I have confirmed that fopen is allowed and active. The other site does not have 24 hour support and I could not verify it in there docs so I had to email in my question. I'd be surprised if they didn't have it active.

Do you have any other possibilities for me to chase down?

Cheers!
Jules
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36715528
Normally you set the return value of 'fopen' to a handle variable so you can actually use the connection.  http://us.php.net/manual/en/function.fopen.php
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Comment

by:Jules Webb
ID: 36715574
I did see that previously and tried adding
$handle = fopen ....
but it didn't work. I tried it again, but I'm still getting the same error.  

Was this what you were referring to?
0
 
LVL 2

Author Comment

by:Jules Webb
ID: 36715585
This is what I'm following: http://ee-spotlight.com/reviews/disqus_comments
If you scroll down half way you'll see the php
They didn't include $handle =  which is why I left it off.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36716584
The PHP environment for cron jobs is different from the environment you've got when running a web script.  Here is something that I have done in the past to identify the different variables, which might include the current working directory, the paths to a data base, etc.

1. Add ob_start() to the top of the cron job.
2. Just before the logical end of the cron job add phpinfo();
2. At the logical end of the cron job, collect the output buffer and email it to yourself.
<?php // cron.php
error_reporting(E_ALL);
ob_start();
echo "Hello World";
phpinfo();
$msg = ob_get_clean();
mail('You@Your.org', 'Cron Output', $msg);

Open in new window

0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 total points
ID: 36718511
Ok, they're just using the 'fopen' to activate something at the URL instead of actually using the contents.  Then probably the second host isn't allowing URLs in the file statements.  You can find out by running 'phpinfo()' in a file.  It will show a status page and tell you if 'allow_url_fopen' is On of Off.
<?php
phpinfo();
?>

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36718516
As Ray said, your command line PHP environment is not necessarily the same as the web server environment.  You can run that same phpinfo() page in the command line.  It's just harder to read.
0
 
LVL 2

Author Comment

by:Jules Webb
ID: 36719845
@Ray_Paseur
I added the cron job you provided, below is the email I received. I'll let you interpret because I don't understand it's implication.

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `<?php // cron.php error_reporting(E_ALL); ob_start(); echo "Hello World"; phpinfo(); $msg = ob_get_clean(); mail('me@email.com', 'Cron Output', $msg); '


@DaveBaldwin
I checked phpinfo on both sites and allow_url_fopen is on in both cases
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 36719926
Looks like the cron environment did not interpret the PHP file through the PHP interpreter.  Even if it had, you would not be likely to receive an email sent to me@email.com.  Have you asked your hosting company about this?  They have probably heard about it before and may have a FAQ tip for you.
0
 
LVL 2

Author Comment

by:Jules Webb
ID: 36720100
@Ray_Paseur
    Even if it had, you would not be likely to receive an email sent to me@email.com  
    I edited my email out so I wouldn't be broadcasting it on experts exchange.

I am on chat with my host asking "about this"  I'll post back, hopefully with some useful info:)

jules
0
 
LVL 2

Author Comment

by:Jules Webb
ID: 36720409
I spent an hour on chat help and the tech ended up submitting a ticket.  He did say he now understood why @Ray said: the cron environment did not interpret the PHP file through the PHP interpreter.

Before I submitted to experts exchange I used their help chat, but since everything looked fine and looked like it was a php issue they sent me on my way, which is when I turned to you guys.  

I don't know if there is anything else you guys can help me with or not, but I"m going to leave this open for now and see what evolves form my help ticket.

Thank you both for your help!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36720442
What will evolve from the help ticket will be this:  They will either set things up so that the PHP parser gets involved with the cron job, or they will tell you how to do it.  Anything less, and they deserve to lost a customer.  Every hosting provider is a little bit different.  Are you on GoDaddy or 1and1 by any chance?  If so, you might consider a move to ChiHost.com, DreamHost, Liquidweb, or HostGator.  All of those are very professional and offer great tech support.  I use and recommend ChiHost.  Call the 1-800 number on their web site and ask for Nick Gilbert.  He is honest and helpful.  They can usually move your web site in a matter of minutes.

All the best,
~Ray
0
 
LVL 2

Accepted Solution

by:
Jules Webb earned 0 total points
ID: 36792914
@Ray - I'm using HostGator. I agree, they are very professional and their support chat is great.  The responded to the ticket within 10 minutes (maybe even less) with a solution.  I've added the code below in case anyone is curious or finds it useful in the future.

I haven't heard of ChiHost.com before, I'll check them out.

Thanks for your help!
// Added to .htaccess file to Ensure that the php.ini with allow_url_fopen turned on is being read
<IfModule mod_suphp.c>
 suPHP_ConfigPath /home/yeowzah
 <Files php.ini>
   order allow,deny
   deny from all
 </Files>
</IfModule>

// PHP file - removed brackets
// Before
fopen('[http://mysite.com/?ACT=40]','r');

// After
fopen('http://mysite.com/?ACT=40','r');

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36794365
If you're on HostGator and you're happy with the support (I have been) there is no reason to move.  Best of luck with it, ~Ray
0
 
LVL 2

Author Closing Comment

by:Jules Webb
ID: 36902316
Thanks for the help guys!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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