window 下nginx+php curl 超时
来源:互联网 发布:改之理 源码 编辑:程序博客网 时间:2024/05/17 02:34
问题:apache+php 能正常访问,换成nginx+php-cgi 就无法使用curl 。
测试脚本:
<?php// create a new cURL resource$ch = curl_init();// set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL, "http://localhost/token.php");curl_setopt($ch, CURLOPT_HEADER, 0);// grab URL and pass it to the browsercurl_exec($ch);// close cURL resource, and free up system resourcescurl_close($ch);?>
解决:
参考:
http://stackoverflow.com/questions/13813667/php-curl-timing-out-but-cli-curl-works
Nginx does not spawn your php-cgi.exe processes for you. If you came from Apache like me and used mod_fcgid, you will find that you have many php-cgi.exe processes in the system.
Because Nginx does not spawn the PHP process for you, you will need to start the process yourself. In my case, I have php-cgi.exe -b 127.0.0.1:9000
running as a service automatically. Nginx then pushes all requests for PHP to the PHP handler and receives a response.
Problem: PHP-FPM does not work on windows (as of 5.4.9). FPM is a neat little process manager that sits in the background and manages the spawning and killing of PHP processes when processing requests.
Because this is not possible, on Windows, we can only serve 1 request at a time, similar to the problem experienced here.
In my case, the following happens: Call a page in my application on sometestsite.com
which makes a call to php-cgi.exe
on 127.0.0.1:9000
. Inside, a CURL request calls a page on endpoint.sometestsite.com
. However, we are unable to spawn any new PHP processes to serve this second request. The original php-cgi.exe is blocked by serving the request that is running the CURL request. So, we have a deadlock and everything then times out.
The solution I used (it is pretty much a hack) is to use this python script to spawn 10 PHP processes.
You then use an upstream block in nginx (as per the docs for the script) to tell nginx that there are 10 processes available.
Things then worked perfectly.
Having said that, please do not ever use this in production (you are probably better off running nginx and php-fpm on Linux anyway). If you have a busy site, 10 processes may not be enough. However, it can be hard to know how many processes you need.
However, if you do insist on running nginx with php on windows, consider running PHP-FPM within Cygwin as per this tutorial.
- window 下nginx+php curl 超时
- windows下PHP + Nginx curl访问本地超时
- windows下PHP + Nginx curl访问本地超时
- windows下PHP + Nginx curl访问本地地址超时卡死问题的解决方案
- windos nginx curl 超时
- php curl 设置超时
- php curl 超时处理
- php之curl设置超时
- PHP curl 超时时间设置
- php的curl超时参数
- window下nginx+php配置安装篇
- window下的nginx+php的配置
- nginx + php 在window下的安装
- window下的nginx+php的配置
- window 下 nginx php 环境搭建
- php nginx超时出错
- nginx+php下curl请求https报502错
- nginx+php在 window下 自动退出 php-cgi解决方案
- bzoj1497 最大获利 最大权闭合图
- 如何获得线程的返回值?
- Unity3D技术之资源数据库 (AssetDatabase)详解
- 第十二周项目3-用递归方法求解(3)用递归函数求两个数的最大公约数
- 优化算法——牛顿法(Newton Method)
- window 下nginx+php curl 超时
- 非洲小孩(南阳oj1036)(贪心)
- 第十二周项目3(5)整数换成二进制
- pdo rowCount影响的行数
- sizeof进行结构体大小的判断
- 二叉树 前中后序遍历非递归版本 C++实现
- ubuntu 设置IP
- poj2352 树状数组
- C语言和Java中的文件操作对比