V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
guoyu4126
V2EX  ›  PHP

PHP 修改 HOSTS 本地 CURL 到本地

  •  
  •   guoyu4126 · 2018-10-10 14:13:22 +08:00 · 3702 次点击
    这是一个创建于 1996 天前的主题,其中的信息可能已经有所发展或是发生改变。

    hosts 修改为 127.0.0.1 www.a.com 127.0.0.1 www.b.com

    Nginx 绑定对应域名。网站都可单独访问 但通过 a.com curl post/get 到 b.com 就访问超时

    Curl 中加上了

    curl_setopt($ch,CURLOPT_RESOLVE,[
    	"lvyou.myyoger.com:127.0.0.1"
    ]);
    

    也是不可以。。

    GuzzleHttp 也访问超时。

    $client = new Client();
    $request = $client->request('GET', $baseUrl, [
    'query' => $params
    ]);
    

    报错信息:PHP Fatal error: Maximum execution time of 30 seconds exceeded

    Curl 到外网就没问题

    3 条回复    2018-10-16 12:16:10 +08:00
    maojy1989
        1
    maojy1989  
       2018-10-10 14:21:25 +08:00
    改成这样试试,curl 的 resolve 好像需要指定端口
    curl_setopt($ch,CURLOPT_RESOLVE,[
    "lvyou.myyoger.com:80:127.0.0.1"
    ]);
    mokeyjay
        2
    mokeyjay  
       2018-10-10 15:57:26 +08:00   ❤️ 1
    guoyu4126
        3
    guoyu4126  
    OP
       2018-10-16 12:16:10 +08:00
    @mokeyjay 解决掉了 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5446 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:50 · PVG 16:50 · LAX 01:50 · JFK 04:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.