PHP unable to fully use CPU cores

Hello,
we have a Linode16GB (6CPU) with CentOS 7 64bit.

When doing a PHP script on this Linode (to import products on magento from an XML file) the CPUs are not used at all but system JUST uses 1/6 of the total CPU resources (Load Average 1.0).

I suppose it's a limitation of PHP (it's not multithread by default?).

We expect all 6 CPUs to be fully exploited or almost!

I have made also a PHP script to stress CPU:

<?php
for($i = 0; $i < 1000000000; $i++) {
$a += $i;
}

But even in this case only one CPU is 100%.
If I run the file 6 times the percentage of CPU usage arrives correctly at 600% (100% x6)

Has anyone already had this problem on CentOS?
How can I solve it to use all CPUs with this import?

Thanks a lot to everyone for the support
Kind regards,
Gian Marco.

1 Reply

PHP is indeed not multi-threaded by default which is why you are experiencing this. You might look into "php pthreads" (google it) if these are command line only scripts.

However, for use in web sites I don't believe there is any real good solution. In fact, probably not a good idea for websites as one misbehaving page load could bring your server to a halt for a while.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct