Warning: file_get_contents()...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Warning: file_get_contents()...

Post by SidewinderX »

In console:
stssquad@rps [~/www/squadstats]# php update.php
Output:
Warning: file_get_contents(): SSL: fatal protocol error in /home/stssquad/public_html/squadstats/update.php on line 16
https://www.novaworld.com/Players/Stats ... 7&p=616065
No log handling enabled - turning on stderr logging
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Code:

Code: Select all

<?php
include("config.php");
error_reporting(E_ALL);

$result40 = mysql_query("SELECT * FROM " . $dbtable , $db);
while ($row40 = mysql_fetch_assoc($result40))
{

$pid = $row40['pid'];

//Gets the content of the submited URL;
$url = "https://www.novaworld.com/Players/Stats.aspx?id=".$row40['pid']."&p=616065";

print "$url\r\n";

/*line 16 */ $content = file_get_contents($url);

//Strips the tags of the $content;
$strip = strip_tags($content);
...
Why is it generating the warnings?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

https isn't an internal protocol, it's "ssl"
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Warning: file_get_contents()...

Post by volka »

That page is served by an iis5 server.
Maybe you have an old php (or openssl) version?
http://de2.php.net/wrappers.http wrote:Warning

When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To workaround this, you should lower your error_reporting level not to include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning for you. If you are using fsockopen() to create an ssl:// socket, you are responsible for detecting and suppressing the warning yourself.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

PHP Version 5.1.6
OpenSSL Version OpenSSL 0.9.7a Feb 19 2003
I'll update SSL and see if that does anything...

Do the SSL warnings have anything to do with the latter error? Even if i set my error reporting to lower, I get still get their error.
No log handling enabled - turning on stderr logging
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Hm. What does

Code: Select all

<?php
include("config.php");
error_reporting(E_ALL); 
var_dump( extension_loaded('snmp') );
echo "<br />\n", phpversion(), "<br />\n";
$result40 = mysql_query("SELECT * FROM " . $dbtable , $db); 
...
print?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

stssquad@rps [~/www/squadstats]# php update.php
bool(true)
<br />
5.1.6<br />
Warning: file_get_contents(): SSL: fatal protocol error in /home/stssquad/public_html/squadstats/update.php on line 15
https://www.novaworld.com/Players/Stats ... 7&p=616065
No log handling enabled - turning on stderr logging
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
Creating directory: /var/net-snmp
Failed to create the persistent directory for /var/net-snmp/snmpapp.conf
read_config_store open failure on /var/net-snmp/snmpapp.conf
ok, i managed to get my ssh back, and those are the results
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You have the http://de2.php.net/snmp extension enabled. The output after
Warning: file_get_contents(): SSL: fatal protocol error in /home/stssquad/public_html/squadstats/update.php on line 15
https://www.novaworld.com/Players/Stats ... 7&p=616065
comes from this extension (I think...)
The strange thing is: Again that's a bug that should have been fixed in php 4.3.x
see http://bugs.php.net/bug.php?id=32613
Asmodeux
Forum Newbie
Posts: 9
Joined: Fri Apr 25, 2008 10:21 am

Re: Warning: file_get_contents()...

Post by Asmodeux »

I'm having problems with this as well. I get

Warning: file_get_contents() [function.file-get-contents]: SSL: fatal protocol error

I'm using PHP 5 so this should not be a problem if I understand

$rssURL = 'https://tbe.taleo.net/NA3/ats/servlet/R ... bVersion=0'
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->load(file_get_contents($rssURL));

Of course if I try some URL like this, everything is fine

http://rss.cbc.ca/lineup/money.xml
Asmodeux
Forum Newbie
Posts: 9
Joined: Fri Apr 25, 2008 10:21 am

Re: Warning: file_get_contents()...

Post by Asmodeux »

Saw this on that POST
When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To workaround this, you should lower your error_reporting level not to include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning for you. If you are using fsockopen() to create an ssl:// socket, you are responsible for detecting and suppressing the warning yourself.
But I'm using PHP 5 so I don't think I need this. Beside, I don't find how to lower the error_reporting level

Any help :?
Post Reply