简体   繁体   English

服务器之间的PHP cURL问题,返回传递可能无法捕获响应

[英]Issues with PHP cURL between servers, return transfer probably wont catch the response

I have a really weird behavior going on. 我的行为很奇怪。

I'm hosting a tracking software for users, that mainly logs mobile traffic. 我正在为用户托管一个跟踪软件,该软件主要记录移动流量。 Now, the path is as follows: 现在,路径如下:

1. My client gets a php code snippet to put in his website. 1.我的客户得到了一个php代码片段以放入他的网站。

2. This code sends a cURL post (based on predefined post fields like: visiotr IP, useragent, host etc) to my server. 2.此代码向我的服务器发送一个cURL帖子(基于预定义的帖子字段,例如:visiotr IP,useragent,host等)。

3. my server logs the data, and decide what the risk level is. 3.我的服务器记录数据,并确定风险级别。

4. it then responds the client server about the status. 4.然后,它向客户端服务器回复状态。 That is, it sends "true" or "false" back to the client server. 也就是说,它将“ true”或“ false”发送回客户端服务器。

5. client server gets that r esponse, and decides what to do (load diffrent HTML content, redirect, block the visitor etc). 5.客户端服务器获得响应,并决定要做什么(加载不同的HTML内容,重定向,阻止访问者等)。

The problem I'm facing is, for some reason, all the requests made from my client's server to my server, are recorded and stored in the a log file, but my clients report of click loss as if my server sends back the response, but their server fails to receive those responses or something. 由于某种原因,我面临的问题是,从客户端服务器到服务器的所有请求都记录并存储在一个日志文件中,但是我的客户端报告点击丢失,就像服务器返回响应一样,但他们的服务器无法收到这些响应或其他内容。

I may note that, there are tons of requests every minute from different clients' servers, and from each client himself. 我可能注意到,每分钟都有来自不同客户端服务器以及每个客户端本人的大量请求。

Could the reason be related to the CURL_RETURNTRANSFER not getting any response ? 原因可能与CURL_RETURNTRANSFER没有得到任何响应有关吗? or, maybe the problem is cURL overload ? 或者,也许问题是cURL重载?

I really have no idea. 我真的不知道。 My server is pretty fast, and uses only 10% of its sources. 我的服务器运行非常快,并且仅使用其源的10%。

Thanks in advance for your thoughts. 预先感谢您的想法。

You touched very problematic domain - high load servers, you problem can be in so many places, so you will have to really spend time to fix it, or at least partially fix. 您碰到了非常有问题的域-高负载服务器,问题可能出在很多地方,因此您将不得不花费时间来修复它,或者至少要部分修复。

First of all, you should understand what is really going on, check out this simplified scheme: 首先,您应该了解实际情况,并查看以下简化方案:

  1. Client's php code tries to open connection to your server, to do this it sends some data via network to your server 客户端的php代码尝试打开与您服务器的连接,为此,它会通过网络将一些数据发送到您的服务器
  2. Your server (I suppose apache) tries to accept it, if it has resources - check max connections properties in apache config 您的服务器(我想是apache)尝试接受它,如果它有资源-请检查apache配置中的最大连接属性
  3. If server can accept connection it tries to create new thread (or use one from thread pool) 如果服务器可以接受连接,它将尝试创建新线程(或使用线程池中的一个)
  4. After thread is started, it runs your php script 线程启动后,它将运行您的php脚本
  5. Your php script do some work, connecto to db and sends response back via network 您的php脚本做了一些工作,连接到数据库并通过网络发送回响应
  6. Client waits till the answer from p5 or closes connection because of timeout 客户端等待直到来自p5的答案或由于超时而关闭连接

So, at each point you can have bottleneck: 因此,您可能会遇到瓶颈:

  1. Network bandwidth 网络带宽
  2. Max opened connections 最大打开连接数
  3. Thread pool size 线程池大小
  4. Script execution time 脚本执行时间
  5. Max database connections, table locks, io wait times 最大数据库连接数,表锁,io等待时间
  6. Clients timeouts 客户超时

And it is not a full list of possible places where problem can occur and finally lead to empty curl response. 它不是可能发生问题并最终导致空卷曲响应的可能位置的完整列表。

From the very start I suggest you to add logging to both PHP codes (clients and servers) and store all curl_error problems in some text file, at least you will see what problems occur often. 从一开始,我建议您将日志记录添加到两个PHP代码(客户端和服务器)中,并将所有curl_error问题存储在某个文本文件中,至少您会看到经常发生什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM