PHP CURL is too slow for localhost

后端 未结 4 1487
暗喜
暗喜 2020-12-17 22:26

I have setup two apps in my WAMP environment. Performance of both the sites is OK. They return data in less than a second. The problem is that when I curl one site from anot

相关标签:
4条回答
  • 2020-12-17 23:05

    I had the same problem and finally discover that it was coming from two facts :

    1. I use Mac OS X Mavericks
    2. I accessed my project via the URL http://myproject.local/ because I put a line 127.0.0.1 myproject.local in /etc/hosts

    It is because the .local tld is reserved for Bonjour service, and this since Mac OS X Lion (10.7).

    Changing the tld for something else fixed the problem.

    0 讨论(0)
  • 2020-12-17 23:09

    If you are using *.local TLD, you can solve this and enjoy fast loading times by adding both, IPv4 and IPv6 entries in the hosts file

    127.0.0.1   test.local
    ::1         test.local
    

    Best

    0 讨论(0)
  • 2020-12-17 23:11

    Yes, is a DNS lookup problem.

    On Windows 7 x64 i managed to overcome this issue

    (curl call between applications on different ports in localhost) by editing the host file ( C:\Windows\System32\drivers\etc ).

    Un-comment on the line that says: 127.0.0.1 localhost , reboot and you're done.

    0 讨论(0)
  • 2020-12-17 23:28

    I solved this problem by setting up different virtual hosts such as sitea.dev and siteb.dev If you use the same host for both sites on your localhost Windows machine, then you get a long delay (the same as if there is a Fatal PHP error). It's not a problem with Curl since file_get_contents(url) gave me the same issue.

    0 讨论(0)
提交回复
热议问题