I have a URL, example.com/api-handler/handler1.php.
One of our SMS service provider push data to the above URL.
The URL above contains a lot of condition, and takes 20-30 seconds to process the data.
Due to huge processing time, the SMS service provider is encountering some performane issue at their end.
What i have did so far, is created another URL with same code i.e. example.com/api-handler/handler2.php.
And then modified the code of handler1.php. Now the handler1.php just takes the data and post it to handler2.php using CURL.
I did it because i thought it will respond the SMS server within 2-3 seconds, but the processing time is still the same.
I can use sessions to get rid of this, but cannot use sessions as the data we are receiving are so frequent.
Is there any other way to respond faster to the service provider on handler1.php and then process the data on handler2.php later?
答案 0 :(得分:1)
问题是PHP中的curl请求被阻止。这意味着您的第一个文件handler1.php
将等到handler2.php
处理完所有内容。
最好的解决方案是使用适当的队列服务:从handler.php
将数据添加到队列中,然后第二个文件将对其进行处理。
一个更简单,更不可靠的解决方案是在cURL请求上设置一个较低的CONNECTION_TIMEOUT
值,以便您的第一个脚本停止等待cURL请求完成:
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);