file_get_contents失败w /空异常 [英] file_get_contents fails w/ empty exception

查看:89
本文介绍了file_get_contents失败w /空异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的file_get_contents行为。我们在代理之后,所以我需要设置file_get_contents的上下文。奇怪的是,在我的电脑上它工作正常,但在其他PC或其他位置,它不会工作,运行到max_execution_time超时。

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 () . "\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n",
                            '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

我觉得很奇怪的是,警告中没有错误...我们不认为它可能是代理服务器,因为我使用相同的代理无处不在,也可以使用不同的代理 - 相同的行为,在我的电脑上工作,在别人不是。我也尝试在其他PC上禁用防火墙和UAC以及其他安全服务,但是效果不佳...我们不知道可能是什么原因。

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.

你对我有什么想法吗?

推荐答案

我们终于找到了解决方案。这不是网络相关的。这是一个包含在Google App Engine启动器安装程序中的PHP 5.5的错误。指定时

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

在app.yaml中,会出现上述症状。当我们将运行时更改为

in the app.yaml, the above mentioned symptoms occur. When we change the runtime to

runtime: php

它可以正常使用代理和一切。这可能会带来一些问题,因为Google已经不赞成使用runtime:php,并且您只能将具有runtime:php55的应用程序上传到App Engine服务器。但我认为一个合理的解决方法是使用runtime:php在本地开发,并将其更改为runtime:php55,仅用于上传 - 但我不知道这是否会产生其他影响...

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...

我们昨天经历的另一个原因是IPv6。在App Engine Launcher v1.9.23中,它有助于在您的PC的entwork设置中完全禁用IPv6。重新启动后,GAE Launcher的php-cgi.exe通过IPv4代理正确连接。

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.

这篇关于file_get_contents失败w /空异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆