简体   繁体   中英

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.

2. This code sends a cURL post (based on predefined post fields like: visiotr IP, useragent, host etc) to my server.

3. my server logs the data, and decide what the risk level is.

4. it then responds the client server about the status. That is, it sends "true" or "false" back to the client server.

5. client server gets that r esponse, and decides what to do (load diffrent HTML content, redirect, block the visitor etc).

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 ? or, maybe the problem is cURL overload ?

I really have no idea. My server is pretty fast, and uses only 10% of its sources.

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
  2. Your server (I suppose apache) tries to accept it, if it has resources - check max connections properties in apache config
  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
  5. Your php script do some work, connecto to db and sends response back via network
  6. Client waits till the answer from p5 or closes connection because of timeout

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
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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