file_get_contents失败,带有空异常
I have a strange behaviour of file_get_contents. We are behind a proxy, so I needed to set the context of file_get_contents. The strange thing is, on my PC it works fine, but on other PC or at other location it won't work, running into the max_execution_time timeout.
if ($requestType == 'GET') {
$context = [
'http' => [
'method' => 'GET',
'header' => "Authorization: " . dbQueryHelper::getApiKey () . "
" . "Content-Type: application/x-www-form-urlencoded
",
'proxy' => getenv ( 'PROXY' ),
'request_fulluri' => true
],
'ssl' => array(
'SNI_enabled' => false, // Disable SNI for https over http proxies
'proxy' => getenv('PROXY'),
'request_fulluri' => true,
"verify_peer"=>false,
"verify_peer_name"=>false,
)
];
}
$context = stream_context_create ( $context );
$dataraw = [
'email' => getenv('DEVMAIL'),
'userEmail' => $user->getNickname(),
'production' => getenv('PROD')
];
$data = http_build_query ( $dataraw );
$context = dbQueryHelper::getContext ( 'GET' ); // this gets the context from above
$result = file_get_contents ( getenv('RESTAPIURL') . '/getPernrByEmail?' . $data, false, $context );
$result = json_decode ( $result, true );
I also get no error message on the other PCs, only
Warning: file_get_contents(...): in C:\trainingplan\lib\common.php on line 79
I think the strange thing is that the warning contains no error... We don't think it could be the proxy because I use the same proxy everywhere and can also use different proxies - same behaviour, on my PC it works, on others not. I also tried with disabling Firewall and UAC and other security services on other PCs, doesn't work as well... We have no clue what could be the root cause.
Do you have any idea for me?
We finally found the solution. It was not network related. It is a bug with PHP 5.5 contained in the Google App Engine Launcher Installer. When specified
runtime: php55
in the app.yaml, the above mentioned symptoms occur. When we change the runtime to
runtime: php
it works fine with proxy and everything. This could be kind of problematic, as Google already deprecated usage of "runtime: php" and you can only upload applications with "runtime: php55" to the App Engine servers. But I think a reasonable workaround would be to develop locally with "runtime: php" and change it to "runtime: php55" only for the upload - but I have no idea if that could have other impacts...
Another cause we experienced yesterday was IPv6. In App Engine Launcher v1.9.23 it helps to disabled IPv6 completely in the entwork settings of your PC. After a restart the php-cgi.exe of GAE Launcher connects correctly through the IPv4 proxy.