I am experiencing an intermittent issue with the fpassthru function, where I am being given the following error which is causing me to have to exit out the script. This is the error I am getting:
Warning:
fopen(http://www.devcrm.lan/rw/category/?session_id=29cc6ecc068bcc1a3862cadb8b9d09c5&admin_sess_id=&g_id=W&cat_id=226&d_id=0&pdid=0&sale=0&page=0&position=&slug=womens/sale/&ajax=0&view_all=0&all=0&c_code=RW&u_region=RW&c_id=1&filter_cat_id%5B%5D=&filter_size%5B%5D=&filter_colour%5B%5D=&filter_price%5B%5D=&HTTP_USER_AGENT=Mozilla%2F5.0+%28Windows+NT+6.1%3B+WOW64%3B+rv%3A10.0.2%29+Gecko%2F20100101+Firefox%2F10.0.2&user_http_host=www.devcrm.lan&user_mobile_config=0)
[function.fopen]: failed to open stream: HTTP request failed! in
/var/www/vhosts/dev/devcrm/shop/index.php on line 213
This is the area of my code where I am using fpassthru. Unfortunately, I am forced to use this function (at the moment, anyway) due to legacy code issues. It is used to send through maintain the $url_parameters when moving from page to page.
$options = array(
'http' => array(
'max_redirects' => 5,
'timeout' => 1,
)
);
$context = stream_context_create($options);
$fpthruPath = URL . "category/" . $url_parameters;
$fp = fopen($fpthruPath, 'rb', false, $context);
if ( false !== $fp ) {
fpassthru($fp);
fclose($fp);
}
exit();
The strange thing about this is that if I take the URL that I am inserting into fopen and stick it in the browser – it works! Also, it only seems to throw this error the first time I go to the page. Is this an Apache setting issue?
OK, after at least a couple of weeks of head-scratching I have found that the ‘timeout’ HTTP setting I am passing into
stream_context_createis causing the fopen to fail. When I comment this out I no longer get the failed to open stream: HTTP request failed! warning from fopen.I am not sure, however, why this has become a problem since upgrading to 5.3.10 as this was never an issue when using 5.1.6. I have had a look around for some 5.3 performance posts, but can’t find much. Understandably, I have grave concerns over releasing this to a live environment as if something that works in 5.1.6 now struggles, presumably due to the limited timeout, in 5.3.10 then are there performance issues with the newer version of PHP that aren’t documented? There have been no other coding changes between the script that fails (intermittently) on 5.3.10, but always works on 5.1.6.
I’m not sure whether to remove the timeout or just increase it to 5 or something like that.