Ask the following questions about php asynchronous programming


First of all, I encountered a scenario problem and wanted to solve it. I’m not sure if threads can solve it. Because I don’t understand it very well. I hope Daniel can give me some advice.
My question is:
Now we are going to provide an API for users to upload a voice file. After processing, the API returns keywords contained in several groups of voice files, which can also be said to be knowledge points, labels, etc.
The inside of API is to call Baidu’s public API service for voice recognition into text after getting the binary data of the voice file, and then use the text to call the internal service of a text recognition tag we made ourselves, and finally output some tag information to the caller.

Because it is a Alibaba Cloud server, the official said that there is no restriction on uplink bandwidth, but when we request Baidu Voice API internally, it is outgoing, for example, we only bought a fixed 10M.

In this way, when the amount of concurrency comes up, the traffic from the server to Baidu is quite amazing, although we are currently only short voice files within 60S. …

My understanding of this resource bottleneck is:

1. The bandwidth is not enough, can it be solved permanently by replacing it with pay-per-view bandwidth?
2. are there bottlenecks in i/o? I don’t know much about the principle of operating system … (I’m currently trying to chew the computer foundation …)
3. Are there problems with other memory resources such as Central Processor?

Before, a great god pointed out that it can be replaced by asynchronous notification callback to control concurrent traffic. However, we still want to return the results to the user in real time, considering that the user’s scenario is not very suitable to actively query and wait for the results.

Returning to the thread point, what I actually want to realize is: can this request not occupy a process all the time? When I go to ask Baidu, can this process suspend sleep without occupying resources, and when Baidu returns a result, activate this process to continue working? Moreover, Baidu’s API also has an asynchronous callback mode. It would be better if I did not wait for Baidu’s processing results online, but received the notification asynchronously and then continued to start the previous process to continue working.

I have seen some content about concurrency before and learned that there is an Swoole: PHP asynchronous network communication engine for production environment. It sounds interesting, but I don’t know whether this scene is suitable or not, and whether it can solve the final problem.

May I describe a lot of slots, please forgive me …

Please also ask Daniel to give directions, thank you!

Your aim is actually to cut the peak. Peak clipping can be done in a queue. A simple understanding is like a dam, the external concurrent quantity is uncontrollable, but the dam can convert the external water flow into controllable water flow (opening gate) so as not to burst downstream!