PHP +卷曲:简单的测试脚本不工作(一台机器上) [英] PHP + cURL: simple test script not working (on one machine)

查看:152
本文介绍了PHP +卷曲:简单的测试脚本不工作(一台机器上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下使用卷曲加载一个网页一个非常简单的PHP脚本,并把它显示

I have the following a very simple PHP script that uses cURL to load a web page and to it display

<?php
  $ch = curl_init("http://www.reddit.com/");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  $content = "Hello, World!";
  $content = curl_exec($ch);
  curl_close($ch); 
  echo $content;
?>

在我的本地机器,它工作得很好 - 但不是我的服务器上。在这里,我得到了在Firefox中连接被重置的错误。引起麻烦的线似乎是 $内容= curl_exec($ CH); 。如果我评论这一行,我能看到的Hello,World!在两台机器上。

On my local machine, it works perfectly well -- but not on my server machine. Here I get a "The connection was reset" error in Firefox. The line that causes trouble seems to be $content = curl_exec($ch);. If I comment this line, I get to see Hello, World! on both machines.

当调用的phpinfo()在两台机器上,在卷曲部分看起来pretty相似。还有什么比在这里,它工作在一台机器上,但没有其他是问题所在。基本上,无论运行的Ubuntu 14.04,与Apache 2和PHP 5.配置或权​​限可能会有所不同。我有点不知所措去哪里找。

When calling phpinfo() on both machines, the cURL section looks pretty similar. What could be the problem here that it works on one machine but not on another. Basically, both run Ubuntu 14.04, with Apache 2 and PHP 5. What configurations or permissions might be different. I'm a bit at a loss where to look.

编辑:arkascha建议,我检查了Apache error.log中文件。事实上,如果我一旦看到下面的错误,因为我执行 curl_exec 命令:

As arkascha suggested, I've checked the Apache error.log file. And indeed, if I see the following error as soon as I execute the curl_exec command:

[核心:声明] [PID 28267] AH00051:孩子的pid 28274退出信号分割故障(11),在/ etc可能核心转储/ Apache2的

推荐答案

我刚刚经历过类似的事情。两个服务器之间的连接卷曲,工作的大部分时间,但在五年将大约一次崩溃。

I've just been through something similar. A CURL connection between two servers, worked most of the time, but would crash approximately one time in five.

当它崩溃,火狐会报告连接被重置和Safari浏览器会告诉我,服务器意外下降的连接​​。 Apache的错误日志中会显示退出信号分割故障(11)

When it crashed, Firefox would report that "the connection was reset" and Safari would tell me that "the server unexpectedly dropped the connection". The Apache error log would show exit signal Segmentation fault (11).

添加的痕迹,我发现这竟是这是导致崩溃的 curl_close 的功能,而不是 curl_exec 这实际上是工作的罚款(且其结果出现在我的日志)。

Adding traces, I discovered it was actually the curl_close function which was causing the crash, not the curl_exec which was actually working fine (and the results of which were appearing in my logs).

最后,我在code明确指出这条线......

Eventually, I pinpointed this line in my code...

curl_setopt($ curlSession,CURLOPT_VERBOSE,真实);

...我是用输出卷曲会议的原始数据到一个日志文件,以进行调试。由于我注释掉该行,错误发生停止

...which I was using to output the raw data of the CURL session to a log file, for debugging purposes. Since I commented-out that line, the error stopped occurring.

如此看来,使用CURLOPT_VERBOSE会导致卷曲崩溃,并采取PHP /阿帕奇它。 (我也看到了从程序员CPP说,有关CPP卷曲同样的事情的讨论。)

So it seems that using CURLOPT_VERBOSE can cause CURL to crash, and take PHP/Apache with it. (I've also seen a discussion from a CPP programmer saying the same thing about CURL on CPP.)

这篇关于PHP +卷曲:简单的测试脚本不工作(一台机器上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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