简体   繁体   中英

PHP run script concurrently?

Let's say I have a PHP script which running a long process which required 10 minutes to complete.

If I execute the script via browser twice, both request will run concurrently or the second request will stay in server queue until the first request complete?

I know the pthreads extension which able to process request concurrently but my server not support that.

This depends on how you set-up apache / nginx / webserver, in a default set-up, they will run concurrently.

I would however not recommend that you expose a long-running php script available to the outside world. You are asking to be DDOSed and also, this is not a good user experience.

If you have a script which you know will take a long time, then have an api endpoint which places the job on a messaging queue like beanstalkd / RabbitMQ and returns a processing / deferred response . You then can have a separate queue worker / many queue workers which would watch the queue and process the jobs in real-time.

See http://kr.github.io/beanstalkd/ or https://www.rabbitmq.com/ or even http://redis.io/topics/pubsub

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