Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member gazman's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    28
    Member #
    566
    Hiya... i'm trying to test a PHP-based XML parser to read an RDF file (original RDF: http://www.freshmeat.net/backend/fm-releases.rdf) but whenever I try to open the URL in PHP I get the following errors:

    Warning: fopen() [function.fopen]: php_hostconnect: connect failed in C:\web\beta\class.RDFParser.php on line 51

    Warning: fopen(http://www.freshmeat.net/backend/fm-releases.rdf) [function.fopen]: failed to create stream: Bad file descriptor in C:\web\beta\class.RDFParser.php on line 51
    Could not read http://www.freshmeat.net/backend/fm-releases.rdf

    I guess the second error is simply a result of the first, but I dont understand why the first occurs at all! I've used the same script on another server without problems... so perhaps it's something to do with this connection..? but i'm able to read the rdf file in my web browser here, so why can't PHP?
    ~GaZ~

  2.  

  3. #2
    Junior Member gazman's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    28
    Member #
    566
    Nevermind... the problem was due to the proxy.

    FYI, if anyone else has a similar prob, you can retrieve a page line by line via a proxy, using the method described in a user comment on the page describing the FOPEN command on php.net... sample code follows:

    Code:
    $myfiles = "http://www.xyz.com/cgi-bin/plz_suche/search_or.cgi?or_plz=$PLZ&or_ort=".rawurlencode($stadt); 
                
    $datei = fsockopen("proxy.wdf.sap-ag.de", 8080, &$errno, &$errstr); 
    if( !$datei ) 
     { 
        echo "proxy not available !"; 
        fclose($resultfile); 
       exit(); 
    } else { 
         fputs($datei,"GET $myfiles/ HTTP/1.0\n\n"); 
          while (!feof($datei)) 
          { 
                  $zeile = fgets($datei,1000); 
          } 
    }
    $myfiles is the page/file you're trying to reach
    $zeile is the line by line src of the page
    ~GaZ~

  4. #3
    Junior Member
    Join Date
    Jul 2004
    Posts
    2
    Member #
    6899
    Thanks for the cool example .... set it up quiet easily

    only thing is our proxyserver adds a bunch of headers to the start of the stream ... any idea how I can strip them off ...

    The only thing I can see is that there is an empty line after the headers ...

    ie ..

    HTTP/1.0 200 OK
    Date: Fri, 30 Jul 2004 09:45:10 GMT
    Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_python/2.7.8 Python/1.5.2 mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 mod_perl/1.26
    mod_throttle/3.1.2
    Content-Type: text/vnd.wap.wml
    X-Pad: avoid browser bug
    X-Cache: MISS from cache2.za.itouchnet.net
    X-Cache: MISS from archive.prv.dev.itouchnet.net
    X-Cache: MISS from cache01.prv.za.itouchnet.net
    Proxy-Connection: close

    <?xml version="1.0"?>
    .... rest of xml doc ...

    Not sure how to do this ....

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    There are easier ways to read an RDF file. I'll have to sift through some old code to find the PHP code I slopped together last year to do this.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  6. #5
    Junior Member
    Join Date
    Jul 2004
    Posts
    2
    Member #
    6899
    Ahha ... I may have a quick win here .... let me know if you see any issue with it ...

    $data = strstr ($data, "<?");

    should strip the header off the file up till the opening tag declaring the xml header ...

    seems to be working fine as I ran this over the weekend monitoring some of our content feeds ...

  7. #6
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    The best way to remove headers is to loop through each line of the string until you reach a line which reads "/r/n/" as headers are terminated by a blank line in HTTP:

    PHP Code:
    while ((!feof ($fhwnd)) && (fgets ($fhwnd) != "\r\n")); 


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com