Php 无法连接到www.googleapis.com端口443:无法访问网络

Php 无法连接到www.googleapis.com端口443:无法访问网络,php,google-api,google-api-php-client,youtube-data-api,Php,Google Api,Google Api Php Client,Youtube Data Api,我正在使用这个库从wordpress网站上从Youtube获取视频和实时流的提要。 该代码在过去一个月内运行正常,但突然它开始出现随机连接错误失败的情况(10次尝试中有2次失败,其他尝试都很正常) 这是我从中得到错误的代码: function googleapis_get_live_event_widget(){ //Youtube Videos and Live Events require_once( get_stylesheet_directory() . '/lib/

我正在使用这个库从wordpress网站上从Youtube获取视频和实时流的提要。

该代码在过去一个月内运行正常,但突然它开始出现随机连接错误失败的情况(10次尝试中有2次失败,其他尝试都很正常)

这是我从中得到错误的代码:

function googleapis_get_live_event_widget(){

    //Youtube Videos and Live Events
    require_once( get_stylesheet_directory() . '/lib/google-api-php-client/src/Google/autoload.php' );
    $GOOGLE_DEVELOPER_KEY = get_field('cce_api_google_developer_key','option');

    $client = new Google_Client();
    $client->setDeveloperKey($GOOGLE_DEVELOPER_KEY);
    $youtube = new Google_Service_YouTube($client);

    try {
        $islive = get_field('cce_live_event','option');

        $opts = array();
        $opts['channelId'] = get_field('cce_api_youtube_channel_id','option');
        if($islive) {
            $opts['eventType'] = 'live';
        }
        $opts['type'] = 'video';
        $opts['maxResults'] = 1;
        $opts['order'] = 'date';


        $live_videos = $youtube->search->listSearch('id,snippet',$opts);

        $data = array();
        $data['live_events'] = $live_videos;
        echo Timber::compile('partials/live_event_widget.twig',$data);

    } catch (Exception $e) {
        $error = array();
        $error['message'] = $e->getMessage();
        echo Timber::compile('partials/error.twig',$error);
        return;
    }


}

add_shortcode('googleapis_live_widget','googleapis_get_live_event_widget');
做一个
curl-vhttps://www.googleapis.com
当尝试失败时,通过服务器中的ssh会导致这种情况:

[~]# curl -v https://www.googleapis.com
* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 216.58.216.202... Connection timed out
*   Trying 2607:f8b0:4009:80b::200a... Failed to connect to     2607:f8b0:4009:80b::200a: Network is unreachable
* Success
* couldn't connect to host
* Closing connection #0
curl: (7) Failed to connect to 2607:f8b0:4009:80b::200a: Network is unreachable
当要求很好时,就像这样:

curl -v https://www.googleapis.com
* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 216.58.216.106... connected
* Connected to www.googleapis.com (216.58.216.106) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*   subject: CN=*.googleapis.com,O=Google Inc,L=Mountain View,ST=California,C=US
*   start date: Oct 21 22:31:24 2015 GMT
*   expire date: Jan 19 00:00:00 2016 GMT
*   common name: *.googleapis.com
*   issuer: CN=Google Internet Authority G2,O=Google Inc,C=US
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.googleapis.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Sat, 31 Oct 2015 11:33:49 GMT
< Vary: X-Origin
< Content-Type: text/html; charset=UTF-8
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Alternate-Protocol: 443:quic,p=1
< Alt-Svc: quic=":443"; p="1"; ma=604800
< Accept-Ranges: none
< Vary: Origin,Accept-Encoding
< Transfer-Encoding: chunked
< 
* Connection #0 to host www.googleapis.com left intact
* Closing connection #0
curl-vhttps://www.googleapis.com
*即将连接()到www.googleapis.com端口443(#0)
*正在尝试216.58.216.106。。。有联系的
*已连接到www.googleapis.com(216.58.216.106)端口443(#0)
*使用certpath:sql:/etc/pki/nssdb初始化NSS
*CAfile:/etc/pki/tls/certs/ca-bundle.crt
卡帕斯:没有
*使用TLS_RSA_和_AES_128_CBC_SHA的SSL连接
*服务器证书:
*主题:CN=*.googleapis.com,O=googleinc,L=Mountain View,ST=California,C=US
*开始日期:2015年10月21日22:31:24 GMT
*到期日期:2016年1月19日00:00:00 GMT
*通用名称:*.googleapis.com
*发行人:CN=谷歌互联网管理局G2,O=谷歌公司,C=美国
>GET/HTTP/1.1
>用户代理:curl/7.19.7(x86_64-redhat-linux-gnu)libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
>主持人:www.googleapis.com
>接受:*/*
> 
未找到
此时,如果我运行页面,提要将正常显示


我应该寻找什么来修复不一致性?

我也有同样的错误,并试图找出原因

这一错误有一定的可能性

  • 您的internet防火墙阻止与google的连接:请尝试
    在您的laravel主机中ping android.googleapis.com
    。或者
    curl-vgcmhttp.googleapis.com
    如果没有响应,那么它将被阻止

  • 打开你的google api的工作端口,我打开的端口通常是
    443
    5528-2230
    。您可以在防火墙中进行配置

  • gcm http.googleapis.com
    有很多ip地址,因此您需要允许从这些ip地址进行连接这是它们的ip地址之一:
    172.217.3.170
    mine通过允许其ip地址范围之间的连接来解决问题。您可以监视防火墙软件中的ip地址

  • 您可以找到google api IP地址的范围和


  • 这取决于您的防火墙配置,您需要与配置防火墙的人一起设置防火墙,因为我假设您在安全的网络环境中工作

    我假设你有问题是因为你的防火墙看到这个答案谢谢,这个问题是通过调整防火墙设置来解决的,允许谷歌使用IPs的范围。如果答案有用,请放弃投票,我们将不胜感激。谢谢