• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1148
  • Last Modified:

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


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
Jules Webb
Asked:
Jules Webb
  • 8
  • 4
  • 3
  • +1
3 Solutions
 
sonawanekiranCommented:
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
 
Jules WebbAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jules WebbAuthor Commented:
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
 
Jules WebbAuthor Commented:
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
 
Ray PaseurCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Jules WebbAuthor Commented:
@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
 
Ray PaseurCommented:
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
 
Jules WebbAuthor Commented:
@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
 
Jules WebbAuthor Commented:
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
 
Ray PaseurCommented:
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
 
Jules WebbAuthor Commented:
@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
 
Ray PaseurCommented:
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
 
Jules WebbAuthor Commented:
Thanks for the help guys!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now