|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-05 09:16 UTC] im at dinexi dot ru
Description: ------------ file_get_contents() and such raises warnings in case of errors when using http stream context. I saw the https://bugs.php.net/bug.php?id=54898&edit=2 and yes, it works. But how I can achieve the adequate behavior when the remote works incorrectly? It will be very sad to change the PHP error reporting level even for this single case and it's hard to find out the problem from the script's code. Test script: --------------- <?php $url = "http://rest.ebay.com/epn/v1/find/item.rss?keyword=key&programid=1&campaignid=123456789&paymentMethod=PayPal&minBids=10&maxBids=20&condition1=New&exclSellerId1=1&exclSellerId2=2&exclSellerId3=О"; $options = array( 'http' => array( 'ignore_errors' => true, ) ); $context = stream_context_create($options); $xmlString = file_get_contents($url, false, $context); var_dump($xmlString); Expected result: ---------------- <Error>An internal error occurred while processing your request</Error> Actual result: -------------- PHP Warning: file_get_contents(http://rest.ebay.com/epn/v1/find/item.rss?keyword=key&programid=1&campaignid=123456789&paymentMethod=PayPal&minBids=10&maxBids=20&condition1=New&exclSellerId1=1&exclSellerId2=2&exclSellerId3=О): failed to open stream: HTTP request failed! in /home/stanis/Work/Fiord/phptest.php on line 43 bool(false) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
I get the expected result when running this test script: $ php stream.php string(283) "<HTML><HEAD>\n<TITLE>Internal Server Error</TITLE>\n</HEAD><BODY>\n<H1>Internal Server Error - Read</H1>\nThe server encountered an internal error or misconfiguration and was unable to\ncomplete your request.<P>\nReference #3.5bdf02cc.1382725055.63671de\n</BODY></HTML>\n" I'm using php 5.4 in ubuntu. $ php -v PHP 5.4.9-4ubuntu2.3 (cli) (built: Sep 4 2013 19:37:07) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans It's worth mentioning that I came across this because I had a different problem. I was trying to get an https url and setting options in my stream context using 'https' as they key which does not work. It should always be 'http' regardless if it's an https connection.