cURL + Laravel Valet + dnsmasq无法正常工作 [英] cURL + Laravel Valet + dnsmasq not working

查看:125
本文介绍了cURL + Laravel Valet + dnsmasq无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行一个PHP脚本,该脚本向在Mac上使用Laravel Valet/dnsmasq设置的.test域运行一个cURL请求时,我得到此错误打印:

when I execute a PHP script which runs a cURL request to a .test domain that is setup on my Mac with Laravel Valet/dnsmasq, I get this error printed :

无法解析:mydomain.test(未找到域名)

Could not resolve: mydomain.test (Domain name not found)

当我在浏览器中测试域时,就可以了.
在终端中运行curl -Ik https://mydomain.test时,我得到HTTP/2 200代码,所以没关系.
当我在终端中运行curl -k https://mydomain.test时,我得到了页面的源代码,所以没关系.

When I test the domain in my browser, it's OK.
When I run curl -Ik https://mydomain.test in the Terminal, I get HTTP/2 200 code, so it's OK.
When I run curl -k https://mydomain.test in the Terminal I get the source code of the page, so it's OK.

为什么它不能与PHP中的cURL一起使用?我很绝望...

Why is it not working with cURL from PHP ? I'm desperate...

更新

由于流行需求;-)这是我的cURL代码.您不能做得更简单:

Due to popular demand ;-) here is my cURL code. You cannot do more simple :

try {
    $ch = curl_init( "http://mydomain.test" );
    curl_exec( $ch );
    dump(curl_error($ch));
    curl_close( $ch );
} catch (Exception $e) {
    var_dump($e);
}

推荐答案

此问题是由curl版本引起的,您可以通过以下方式从终端检查您的curl版本吗?

This problem is caused by curl versions, can you check your curl versions from terminal by

curl --versionphp --ri curl

运行php --ri curl时,您会看到cURL Information => 7.63.0此行.

When you run php --ri curl you will see cURL Information => 7.63.0 this line.

然后,您可以比较您的版本,然后查看哪个curl版本不适用于dnsmasq.

Then you can compare your versions and you see which curl version is not working with dnsmasq.

我遇到了这个问题,我的curl版本在php中为7.64.0.

I encountered this problem and my curl version was 7.64.0 in php.

要解决该问题:

您可以卸载 curl-openssl ,此命令将删除curl-openssl的最新版本:

You can uninstall curl-openssl, this command will remove last version of curl-openssl:

brew uninstall curl-openssl --ignore-dependencies

然后重新启动php:

brew services restart php

重新启动后,php将看到/usr/bin/curl的curl,并且此版本可以访问本地域.

After restarting, php will see curl which is /usr/bin/curl and this version can access local domain.

这篇关于cURL + Laravel Valet + dnsmasq无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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