0

I have a PHP script whose load the 1 CPU of 8 CPUs for 100 percent. Can I share CPU resources to run PHP script faster?

Now when I start my PHP script, it load 1 CPU to 100%. But other have 1-5% load. Because of this my script is performed for 40 second.

Can I share the load across all processors, or this impossible?

4
  • 1
    It's not because you have 7 undercapacity CPUs that your PHP script runs for 40 seconds, it's probably because the script is inefficiently written Commented Sep 4, 2013 at 12:08
  • Can we see the script? Edit it into your question (or a relevant part of it) so people can advise. Commented Sep 4, 2013 at 12:19
  • This script written specially for load cpu for 100 percent. But script loaded only one core on the system. I wont to load other cpus for 100 percent Commented Sep 4, 2013 at 12:27
  • Use "cpuburn" if you want to stress-test your system. Alternatively, run eight parallel requests, some webservers will handle multiple requests in parallel. Commented Sep 4, 2013 at 13:13

2 Answers 2

2

Firstly: if you're CPU bound for 40 seconds chances are you need to rethink your algorithm or your programming language. PHP IMHO still does best as a user facing, HTML/JSON/whatever output format producing engine. That's why it's built on a shared nothing architecture: one request gets one CPU, computes and terminates. You scale this architecture over multiple CPUs by distributing the requests among them.

That said, if a single request takes 40s to complete, you might have luck with using Worker threads, that will you need to spin off your main thread and which can run on your under-utilized CPUs. But again, that's a whole mountain of complexity to scale - think hard before starting down that route.

A probably easier alternative to do-it-yourself thread management is to fork out work to dedicated worker processes. Gearman is a well known framework to help you with this.

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

2 Comments

Thnx for answer. Problem sounds as share cpu core resources to execute php script. No problem with optimization. Issue with share cpu resources
In a sense, if you need to make if faster (by using multiple cores), it's optimization ;) There's no magic bullet here - PHP won't distribute your script to several CPUs for you. If you need that, you have to start managing your own work-load. Another alternative to worker threads are worker pools like those offered by gearman
0

You could use the APC extension http://www.php.net/manual/de/book.apc.php. And store big array's etc. If I am not mistaken this will get stored into the Shared Memory and will be accessable trough all your processors. Also since those variables etc. are cached php won't compile it again that should increase the perfomance of your php application .

Thats the only think I could come up with.

1 Comment

Thnx! But it doesn't help me.

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.