From: gilperon at gmail dot com
Operating system: any
PHP version: 8.0.3
Package: *General Issues
Bug Type: Bug
Bug description:FILE_GET_CONTENTS HANGS ON PHP 8
Description:
------------
In any version of PHP (previous to 8) this bug didnt happen (I've been
using it since 2010) but on PHP 8, the code below hangs indefinately.
Tested on Windows 7, Windows 10, Centos 8 and Centos 7. The code below
just tries to access an external API and, so far, I just managed to get
this bug to happen on this specific URL below (from the API).
<?php
$response =
file_get_contents("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?nCdEmpresa=&sDsSenha=&sCepOrigem=11661690&sCepDestino=88070-480&nVlPeso=1&nCdFormato=1&nVlComprimento=25&nVlAltura=3&nVlLargura=25&sCdMaoPropria=N&nVlValorDeclarado=0&sCdAvisoRecebimento=N&nCdServico=04014&nVlDiametro=0&StrRetorno=xml");
echo $response;
?>
BUT if I add a timeout, the code above works just fine:
<?php
$context = stream_context_create(array(
"http" => array(
"timeout" => 2
)
));
$response =
file_get_contents("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?nCdEmpresa=&sDsSenha=&sCepOrigem=11661690&sCepDestino=88070-480&nVlPeso=1&nCdFormato=1&nVlComprimento=25&nVlAltura=3&nVlLargura=25&sCdMaoPropria=N&nVlValorDeclarado=0&sCdAvisoRecebimento=N&nCdServico=04014&nVlDiametro=0&StrRetorno=xml",0,$context);
echo $response;
?>
I must say that using CURL works just fine, without any timeout, on any
version of PHP. So this is a file_get_contents problem and the only
way I am finding to solve this problem in the short term is using CURL.
Test script:
---------------
<?php
$response =
file_get_contents("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?nCdEmpresa=&sDsSenha=&sCepOrigem=11661690&sCepDestino=88070-480&nVlPeso=1&nCdFormato=1&nVlComprimento=25&nVlAltura=3&nVlLargura=25&sCdMaoPropria=N&nVlValorDeclarado=0&sCdAvisoRecebimento=N&nCdServico=04014&nVlDiametro=0&StrRetorno=xml");
echo $response;
?>
Expected result:
----------------
Response should be printed.
Actual result:
--------------
The code hangs.
--
Edit bug report at https://bugs.php.net/bug.php?id=80931&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80931&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80931&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80931&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80931&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80931&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80931&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80931&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80931&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80931&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80931&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80931&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80931&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80931&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80931&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80931&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80931&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80931&r=mysqlcfg