php fopen:无法打开流:连接超时

时间:2020-04-19 18:07:21

标签: php https fopen

$ php ./fopen_google.php

<?php
$url = 'https://www.google.com'; //this doesn't work, https!
#$url = 'http://www.cmsrs.pl'; //this work with: http
$fp = fopen($url, 'r');
var_dump( $fp );
?>

给我错误:

PHP警告:fopen(https://www.google.com):无法打开流:在第5行的./fopen_google.php中连接超时

我不知道为什么会出现此错误,我尝试使用curl并进行设置:

set_time_limit(10);
ini_set('max_execution_time', 300);

但是我仍然遇到相同的错误。

这是我的curl代码,可为我提供Google的内容:

<?php
$url = 'https://www.google.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$retval = curl_exec($ch);
print_r($retval);
?>

所以我认为连接没有问题,但是php fopen和ssl出了问题

我使用

$ php -v
PHP 7.2.24-0ubuntu0.18.04.4 (cli) (built: Apr  8 2020 15:45:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.4, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans



$ php -i | grep ssl
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
openssl
Openssl default config => /usr/lib/ssl/openssl.cnf
openssl.cafile => no value => no value
openssl.capath => no value => no value

我的主要问题是在我的私人项目中安装“ laravel / ui”:

$ composer require laravel/ui
In RemoteFilesystem.php line 515:

  The "https://packagist.org/packages.json" file could not be downloaded: failed to open stream: Connection timed out  

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...

使用“ fopen”下载google.com内容时,我遇到了相同的错误。

0 个答案:

没有答案