php - file_get_contents(和 wget)非常慢

标签 php linux performance wget

我正在使用 google text to speech api,但由于某些原因,当我通过 php 或命令行连接到它时它真的很慢。

我这样做:

$this->mp3data = file_get_contents("http://translate.google.com/translate_tts?tl=en&q={$text}");  

其中 $text 只是一个 urlencoded 字符串。

我也试过在命令行上通过 wget 来完成:

wget http://translate.google.com/translate_tts?tl=en&q=test

这两种方式都需要大约 20 秒或更长时间。通过 php,它最终确实获取了内容并将它们添加到我服务器上的一个新文件中,正如我所希望的那样。通过 wget 超时连接。

但是,如果我只是在浏览器中转到该 url,它几乎是即时的。

谁能阐明为什么会发生这种情况?

谢谢。

最佳答案

这取决于 Google 解析机器人的方式。您需要伪造 User-Agent header 以伪装成一台计算机。

有关如何进行此操作的一些信息将在此处:

https://duckduckgo.com/?q=php%20curl%20spoof%20user%20agent

关于php - file_get_contents(和 wget)非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18004093/

相关文章:

php - 如何选择多个表将mysql转换为json?

linux - 在 linux 内核 3.12 中使用 leds-pwm susbsystem 控制 LED

javascript - html中有类似 "load header first and body last"的东西吗?

c# - VS2010 与 VS2008 中的字符串排序性能下降

php - 如何使用 json_encode 调用 PHP 中的多个类?

php - 在第三列中插入数据时如何保留两列的唯一组合?

php - 将 1 天添加到 DATETIME 格式值

android - CM7 for Milestone - 在 kernel.org 停机维护时从源代码构建

linux - 发生一般保护异常后获取通知 - Linux 内核

performance - scala中的应用程序监控性能