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.

1
  • Maybe you could post the relevant part of the code so we can figure out what is going on Commented Aug 2, 2019 at 14:05

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.