Jump to content

Multi-threading php in the module


Recommended Posts

Multithreading and php. A nightmare :D 
But there are different solutions like pthreads or parallel. 

But do you really have to run the import in the background? php and prestashop can handle multiple requests at a time, so you can still work in your shop, while the import is handled in another process. 
 

Link to comment
Share on other sites

Thank you for that answer. I see that...😅

I tried in parallel. It works in terminal but not in my webserver so I don't know if we can do with it?

For the multiple process of prestashop is it activated basic? I'm running my function in a back office hook like that, but can't do anything else beside it. Is it the good process ? How can I do this?

public function hookDisplayBackOfficeHeader()
    {
        if (Tools::getIsSet('initProduct')) {
        	$this->initAll();
        }

        $redirect = $_SERVER['REQUEST_URI'] . '&initProduct=1';
        $this->context->smarty->assign(
            [
                'redirect' => $redirect,
            ]
        );
    }

 

(sorry for my bad english)

Edited by QuentinJou (see edit history)
Link to comment
Share on other sites

You can configure how many php processes your webserver is allowed to start. Read here: https://www.php.net/manual/en/install.fpm.configuration.php 

Depending on your php configuration it should be pm.max_children which should be larger than 1. Or like it is written here 

Quote

Inside this file, the most important setting is the pm.max_children setting. It must be greater than the max number of concurrent users you want to simulate during the bench.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...