phpxmllaravelxml-parsingfopen

fopen() cannot read .xml file from connection


I was able to read the .xml file, which is publicly available and accessible from the web browser, in a normal way until today as follows.

$file_handle = fopen($exchanges_file_url, 'r');

However, as of today, I realised that I encountered null values while reading.

when I print the output to the screen with

dd($file_handle);

stream resource @8 ▼ // app/Http/Controllers/InvoiceController.php:603
  timed_out: false
  blocked: true
  eof: false
  wrapper_data: array:2 [▼
    0 => "HTTP/1.1 200 OK"
    1 => "Connection: Close"
  ]
  wrapper_type: "http"
  stream_type: "tcp_socket/ssl"
  mode: "r"
  unread_bytes: 189
  seekable: false
  uri: "http://www.tcmb.gov.tr/kurlar/today.xml"
  options: []
}

My Laravel project is running on my local computer. When I upload the same project to the web server, the .xml file is read without any problems.

Using artisan commands, cache, config, etc... I deleted everything with optimize:clear and one by one, but nothing changed.I turned the modem off and on, changed the ip address and still the result is the same.When I try to read with curl, I get the same result.I also saw that the 'allow_url_fopen' option is 'on' in my php.ini file.I added User-Agent and again the same result, nothing changed.

Can you help me.

I am waiting for a result regarding the answer to my question or an alternative method to be presented.


Solution

  • After changing http -> https taking into account CBro's reply

    $opts=array(
                    "ssl"=>array(
                        "verify_peer"=>false,
                        "verify_peer_name"=>false,
                    ),
                ); 
    
    @fopen($exchanges_file_url, 'r',false, stream_context_create($opts));
    

    after reading the xml file with these settings

    $context = stream_context_create(array('ssl'=>array(
                        'verify_peer' => false, 
                        "verify_peer_name"=>false
                        )));
    
    libxml_set_streams_context($context);
    
    $exchanges = simplexml_load_file($exchanges_file_url); 
    

    error fixed after adding ssl information