xml load error?

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

jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

xml load error?

Post by jdeters79 »

I'm new to PHP, and am trying to implement a basic PHP code to read from two xml files;
http://weather.aero/dataserver_current/ ... urrent.xml

http://weather.aero/dataserver_current/ ... urrent.xml

I'm selectively pulling data from the xml files to be displayed on the webpage. I've been able to get the code to run locally on my machine using Wampserver, however, when I try to run it from the web it doesn't seem to fully "run". Here is the code;

Code: Select all

 
 
  <h1>METAR:</h1>
  
    <?php
        
        $xmlDoc = new DOMDocument();
        $xmlDoc->preserveWhiteSpace = FALSE;
        $xmlDoc->load( "http://weather.aero/dataserver_current/current/metars.current.xml", LIBXML_DTDLOAD|LIBXML_DTDATTR );
 
//      $xmlDoc = DOMDocument::load( "http://weather.aero/dataserver_current/current/metars.current.xml", LIBXML_DTDLOAD|LIBXML_DTDATTR );
 
        $METAR_stations = $xmlDoc->getElementsByTagName( "METAR" );
 
        foreach( $METAR_stations as $METAR_station )
        {
            $METAR_reports = $METAR_station->getElementsByTagName( "station_id" );
            $METAR_report = $METAR_reports->item(0)->nodeValue;
 
            $METAR_texts = $METAR_station->getElementsByTagName( "raw_text" );
            $METAR_text_report = $METAR_texts->item(0)->nodeValue;
 
        if ($METAR_report == "KDLH"){
            echo "<H2>$METAR_text_report</H2>\n";
            }
        }
    ?>
 
    <br />
    <br />
    <h1>TAF:</h1>
    
    <?php
        $xmlDoc = new DOMDocument();
        $xmlDoc->preserveWhiteSpace = FALSE;
        $xmlDoc->load( "http://weather.aero/dataserver_current/current/tafs.current.xml", LIBXML_DTDLOAD|LIBXML_DTDATTR );
 
//      $xmlDoc = DOMDocument::load( "http://weather.aero/dataserver_current/current/tafs.current.xml", LIBXML_DTDLOAD|LIBXML_DTDATTR );
 
        $TAF_stations = $xmlDoc->getElementsByTagName( "TAF" );
 
        foreach( $TAF_stations as $TAF_station )
        {
            $TAF_reports = $TAF_station->getElementsByTagName( "station_id" );
            $TAF_report = $TAF_reports->item(0)->nodeValue;
 
            $TAF_texts = $TAF_station->getElementsByTagName( "raw_text" );
            $TAF_text_report = $TAF_texts->item(0)->nodeValue;
 
        if ($TAF_report == "KDLH"){
            echo "<H2>$TAF_text_report\n</H2>";
            }
        }
?>    
 
 

With regards to it "not fully running". It will usually load the METAR data, and sometimes the TAF data. Also there are some other images on the pages that should also be displayed, but they are not displaying. I've tried to make sense of the error logs, but from what I see it seems like the METAR shouldn't display either. Here is a sample from the error log;
  • PHP Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://weather.aero/dataserver_current/ ... urrent.xml" in /hermes/bosweb/web102/b1025/ipw.handsomedave/public_html/FlightTestWX/index.php on line 42

    PHP Warning: DOMDocument::load() [domdocument.load]: URL file-access is disabled in the server configuration in /hermes/bosweb/web102/b1025/ipw.handsomedave/public_html/FlightTestWX/index.php on line 66

    PHP Warning: DOMDocument::load(http://weather.aero/dataserver_current/ ... urrent.xml) [domdocument.load]: failed to open stream: no suitable wrapper could be found in /hermes/bosweb/web102/b1025/ipw.handsomedave/public_html/FlightTestWX/index.php on line 66

    PHP Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://weather.aero/dataserver_current/ ... urrent.xml" in /hermes/bosweb/web102/b1025/ipw.handsomedave/public_html/FlightTestWX/index.php on line 66
Line 42 mentioned above is actually line 9 in the code pasted above, and line 66 is line 36 above.

As you might notice from the code above (see commented line) I've been trying to dig around on the web to see what "fixes" I can find. I'm not sure if it's code related or server (settings?) related? My hunch is it's server related as, like I mentioned, it will run locally on my machine fine using Wampserver.

Any help would be GREATLY appreciated!
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: xml load error?

Post by Darhazer »

Code: Select all

URL file-access is disabled in the server configuration
You have to enable it (most likely you have to set allow_url_fopen to url) or you have to download the file via curl and import it locally
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

It is "on"

Code: Select all

 
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
 
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
 
; Define the anonymous ftp password (your email address)
;from="john@doe.com"
 
; Define the User-Agent string
; user_agent="PHP"
 
; Default timeout for socket based streams (seconds)
default_socket_timeout = 60
 
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; auto_detect_line_endings = Off
 
 
 
Is it possible that I need to increase the "default_socket_timeout" time? The xml files are rather large, and I'm afraid that the time to parse is quite large. Would increasing the "socket_timeout" help?
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

Tried changing the socket timeout. Didn't make a difference... Any other thoughts out there?

Are there any differences between PHP versions 5.2.12 and 5.3.0 that might cause this? The web server is running 5.2.12, and WampServer is 5.3.0. As I mentioned before, it runs fine locally using WampServer, but does not run from the web server.
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

Any thoughts as to why a page will work when ran locally using WampServer, but not when loaded on a server? .ini file settings?
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: xml load error?

Post by davex »

Hi,

I really think that:
PHP Warning: DOMDocument::load() [domdocument.load]: URL file-access is disabled in the server configuration in /hermes/bosweb/web102/b1025/ipw.handsomedave/public_html/FlightTestWX/index.php on line 66
Is your problem. If URL file access is actually enabled then you shouldn't get this error. All the other errors would be explained by this being the cause.

Just to check did you enable the fopen line or was it already enabled? If you enabled it have you reloaded apache which will reload the PHP module and changes?

Do a:

Code: Select all

<?php phpinfo(); ?>
On a page on your server.

What you want to check is (a) what the config file(s) are and (b) what the value of allow_url_fopen is.

Often the php.ini you find in /etc doesn't apply to the apache module, just the CLI.

Regards,

Dave.
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

I have verified the "allow_url_fopen" is set to "On"


What about this?

;extension=php_domxml.dll

Pretty sure this is required, but is it implemented correctly?
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: xml load error?

Post by davex »

How have you verified allow_fopen_url? Just in the .ini file? Please check the phpinfo() output to be sure it is not being overriden and that you are using the correct .ini and options.

I am not sure if domxml is required but again I think it's not getting that far given the fopen() error being displayed.

Cheers,

Dave.
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

Verified...


Code: Select all

 
 
PHP Version 5.2.12 
 
System  Linux boscgi0503.eigbox.net 2.6.32.2-nx #1 SMP Mon Jan 4 16:14:35 EST 2010 i686  
Build Date  Feb 12 2010 18:19:15  
Configure Command  './configure' '--prefix=/usr/local/lib/php-5.2.12' '--disable-ipv6' '--without-apache' '--with-mysql=/usr' '--with-mysqli' '--with-gd' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-tiff-dir=/usr' '--disable-debug' '--enable-discard-path' '--enable-inline-optimization' '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-memory-limit' '--with-regex=system' '--with-zlib' '--enable-ftp' '--enable-sockets' '--enable-magic-quotes' '--with-gettext' '--enable-wddx' '--with-gdbm' '--with-db4' '--with-freetype-dir=/usr' '--with-curl=/usr' '--with-mhash' '--with-xsl' '--enable-calendar' '--with-mcve' '--with-dom' '--with-iconv' '--with-xmlrpc' '--with-mcrypt' '--with-bzip2' '--with-ming=/usr' '--with-pspell' '--with-openssl' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--with-imap' '--with-kerberos' '--with-imap-ssl' '--enable-bcmath' '--enable-dbase' '--enable-exif' '--with-pdo-mysql'  
Server API  CGI  
Virtual Directory Support  disabled  
Configuration File (php.ini) Path  /usr/local/lib/php-5.2.12/lib  
Loaded Configuration File  /opt/users/ipw/h/a/ipw.handsomedave/php5/php.ini  
Scan this dir for additional .ini files  (none)  
additional .ini files parsed  (none)  
PHP API  20041225  
PHP Extension  20060613  
Zend Extension  220060519  
Debug Build  no  
Thread Safety  disabled  
Zend Memory Manager  enabled  
IPv6 Support  disabled  
Registered PHP Streams  https, ftps, compress.zlib, php, file, data, http, ftp  
Registered Stream Socket Transports  tcp, udp, unix, udg, ssl, sslv3, sslv2, tls  
Registered Stream Filters  zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed  
 
 This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
 
 
 
--------------------------------------------------------------------------------
 
PHP Credits
 
--------------------------------------------------------------------------------
 
Configuration
PHP Core
Directive Local Value Master Value 
allow_call_time_pass_reference On On 
allow_url_fopen On On 
allow_url_include Off Off 
always_populate_raw_post_data Off Off 
arg_separator.input & & 
arg_separator.output & & 
asp_tags Off Off 
auto_append_file no value no value 
auto_globals_jit On On 
auto_prepend_file no value no value 
browscap no value no value 
default_charset no value no value 
default_mimetype text/html text/html 
define_syslog_variables Off Off 
disable_classes no value no value 
disable_functions no value no value 
display_errors STDOUT STDOUT 
display_startup_errors Off Off 
doc_root no value no value 
docref_ext no value no value 
docref_root no value no value 
enable_dl On On 
error_append_string no value no value 
error_log no value no value 
error_prepend_string no value no value 
error_reporting 6135 6135 
expose_php On On 
extension_dir ./ ./ 
file_uploads On On 
highlight.bg #FFFFFF #FFFFFF 
highlight.comment #FF8000 #FF8000 
highlight.default #0000BB #0000BB 
highlight.html #000000 #000000 
highlight.keyword #007700 #007700 
highlight.string #DD0000 #DD0000 
html_errors On On 
ignore_repeated_errors Off Off 
ignore_repeated_source Off Off 
ignore_user_abort Off Off 
implicit_flush Off Off 
include_path .:/usr/local/lib/php-5.2.12/lib/php .:/usr/local/lib/php-5.2.12/lib/php 
log_errors Off Off 
log_errors_max_len 1024 1024 
magic_quotes_gpc On On 
magic_quotes_runtime Off Off 
magic_quotes_sybase Off Off 
mail.force_extra_parameters no value no value 
max_execution_time 300 300 
max_file_uploads 20 20 
max_input_nesting_level 64 64 
max_input_time 60 60 
memory_limit 18M 18M 
open_basedir no value no value 
output_buffering no value no value 
output_handler no value no value 
post_max_size 8M 8M 
precision 12 12 
realpath_cache_size 16K 16K 
realpath_cache_ttl 120 120 
register_argc_argv On On 
register_globals On On 
register_long_arrays On On 
report_memleaks On On 
report_zend_debug On On 
safe_mode Off Off 
safe_mode_exec_dir no value no value 
safe_mode_gid Off Off 
safe_mode_include_dir no value no value 
sendmail_from no value no value 
sendmail_path /usr/sbin/sendmail -t -i  /usr/sbin/sendmail -t -i  
serialize_precision 100 100 
short_open_tag On On 
SMTP localhost localhost 
smtp_port 25 25 
sql.safe_mode Off Off 
track_errors Off Off 
unserialize_callback_func no value no value 
upload_max_filesize 2M 2M 
upload_tmp_dir no value no value 
user_dir no value no value 
variables_order EGPCS EGPCS 
xmlrpc_error_number 0 0 
xmlrpc_errors Off Off 
y2k_compliance On On 
zend.ze1_compatibility_mode Off Off 
 
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

Just trying to do some digging and tried this;

allow_url_include = On

No luck. Came up with this from this article, which obviously recommends this to be set to 'off'.
http://phpsec.org/projects/phpsecinfo/t ... clude.html
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: xml load error?

Post by davex »

Hi,

allow_url_include lets you import (include) PHP scripts into your code from a URL.

This is indeed a big security no no generally and should have nothing to do with your problem.

I'm at a bit of a loss as to what may be causing this error then if you can fopen a URL. Might I suggest you break down your code a little and try to see where it fails e.g. (in pseudo code)

fopen the URL and read the XML file into a buffer
load that buffer into your XML parser/system

See where the failure occurs - this will show if it's the (incorrect) failure of getting data via http or if the XML side is at fault.

Regards,

Dave.
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

I'll give it a shot. Although, as I previously posted, it will run/load fine when opening the file locally using WampServer, but only run into the issue when trying it from the actual webserver.
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: xml load error?

Post by davex »

Well... this url http://weather.aero/dataserver_current/ ... urrent.xml

Just times out eventually for me!

Could it maybe just be that there is a load/delay problem at the other end?

Oh on a second refresh it has loaded but only after a good 45 seconds.

Did you say it worked sometimes and not others? Wonder if it's just getting timed out?

Cheers,

Dave.
jdeters79
Forum Newbie
Posts: 10
Joined: Thu Feb 25, 2010 8:47 pm

Re: xml load error?

Post by jdeters79 »

I believe I have it figured out, I was missing a "break;" in an "if" statement. The code is broken into two separate "php scripts", one for METARs, the other for TAFs. Below is the METAR example.

WAS:

Code: Select all

 
if ($METAR_report == "KDLH"){
            echo "<H2>$METAR_text_report</H2>\n";
            }
        }
 
CHANGED TO:

Code: Select all

 
if ($METAR_report == "KDLH"){
            echo "<H2>$METAR_text_report</H2>\n";
            break;
            }
        }
 
I got to thinking about this because the page was only partially loading from the web server. It was always "crashing" in the METAR portion (i.e. I got to thinking about it hanging up in that portion of the code). I added the break command to both sections, and voile!
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: xml load error?

Post by davex »

:lol: HAPPY DAYS.

Glad you sorted it out. Good luck with the program - looks like a fun thing to play with.

Regards,

Dave.
Post Reply