cURL + Laravel Valet + dnsmasq not working

你离开我真会死。 提交于 2019-11-30 03:41:19

问题


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 :

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

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.

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

UPDATE

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);
}

回答1:


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

curl --version and php --ri curl

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

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

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


For solve that issue:

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

brew uninstall curl-openssl --ignore-dependencies

Then restart php:

brew services restart php

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




回答2:


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

After restarting too the valet: valet restart



来源:https://stackoverflow.com/questions/54688451/curl-laravel-valet-dnsmasq-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!