0

I call Python script via exec blocking function inside php file which is served by Nginx. It works as expected. Python script executes Selenium using webdriver Chrome and returns xml output.

The problem is when I create more requests (2 and more) in the same time. First request is processed (nginx, php, python) and the second waits for finish of the first. They are not parallel executed.

Python script executed directly from shell can be parallel executed without problems.

Peter K
  • 1
  • 2

2 Answers2

1

You have two option.

Multi-Threading

PHP does not support threads natively, but there is this solution. It is still experimental and it requires PHP 7.2+, but if you are already using PHP 7.2+ it will work like a charm.

Multi-Processing

You can make new processes by forking. You can read more about forking in PHP in this answer and more about it as a concept here.

Or you can also do it in the current way with exec(), but you have to put & at the end of the command, so the PHP might pass it to the console and it can run in the background and run the 2nd one.

There is a third way using MQ Engines, but I cannot help with that, but you can read about it too if you are interested. Hope something of these helps.

Martin Dimitrov
  • 1,304
  • 1
  • 11
  • 25
0

PHP isn't directly asyncronious, use the pcntl extencion and look at this

ShiSHcat
  • 83
  • 1
  • 8