Solved

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

Posted on 2011-09-28
16
921 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
  • 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 83

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 109

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 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 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 83

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 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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 109

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 109

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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