What makes a PHP Script run faster?
Moderator: General Moderators
What makes a PHP Script run faster?
Right now i have a program that processes ALOT of data. On my 3Ghz processor with 1 Gb memory it takes over 6 seconds to process aproximately 40 rows of data.
Now, my question is, which has the most impact on running lots of queries with, more memory or more processing power?
Dell is having a special on their servers right now, enabling me to get much cheaper dual core processors. Do you think i should get a single core processor with more Ghz and Memory? or get a dual core which is more expensive?
price is not as huge of an issue, but i need this to run as fast as possible
Now, my question is, which has the most impact on running lots of queries with, more memory or more processing power?
Dell is having a special on their servers right now, enabling me to get much cheaper dual core processors. Do you think i should get a single core processor with more Ghz and Memory? or get a dual core which is more expensive?
price is not as huge of an issue, but i need this to run as fast as possible
It should still be able to process faster than that if it's a dedicated server. Why not try dumping out microtime() in some places to see what's taking the longest.
If there's no single place that's taking longer than it should, maybe your code can be optimized a bit (ie: not generating 100% of the html each loop - use variables for common pieces of code).
If there's no single place that's taking longer than it should, maybe your code can be optimized a bit (ie: not generating 100% of the html each loop - use variables for common pieces of code).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: What makes a PHP Script run faster?
Having a gig of RAM is entirey irrelevent if PHP is limited to using a maximum of 8 meg. Have you increased it from the default?Deemo wrote:On my 3Ghz processor with 1 Gb memory it takes over 6 seconds to process aproximately 40 rows of data.
i tried setting the memory limit higher but it didnt do any good.
the queries are simple queries. Nothing more advanced that a SELECT * FROM Table WHERE ID=1 or an update query. its not even that theres alot of queries, its just that there is so much to process. I would host it up somewhere but i dont have any host to run it off of.
Let me try and explain how my code works and you guys can try and help from there. It starts by getting a simple query, selecting all the tasks from the database. thats stored in a 2 dimentional array of rows an columns. i then start by displaying the due date of the task. thats 3 drop down menus, with number of days (1-31) months (1-12) year (2005-2010). The thing is, this isnt just a normal drop down menu, this is a hidden menu, so when you put it in focus, thats when it appears (see my previous post here). Then it goes on display the client name, project name, and some other miscelaneos data. Finally it starts a new row, but this row is made up of 4 drop down menus, each with 6 items each. Next to each drop down is a text box with the number of hours.
Here is an image of what it looks like
I noticed that it takes longest during the row with the 4 drop down menus. Why do you think this is?
edit: i was looking at xdebug and tryed to install it but i completely lost myself and i dont know what im doing anymore
edit 2: i am 100% sure that the 4 drop down menus are bottlenecking it. When i comment it out, it takes .4 seconds to load the page. ill have to find a way to optimize this now
edit3:
im going to post the code for the problem area. Hopefully someone will notice whats wrong and help me fix it. ask any question about the code, ill try and comment it as best i can
thanks alot for any help you can provide and for actually sitting down and helping me through this 
the queries are simple queries. Nothing more advanced that a SELECT * FROM Table WHERE ID=1 or an update query. its not even that theres alot of queries, its just that there is so much to process. I would host it up somewhere but i dont have any host to run it off of.
Let me try and explain how my code works and you guys can try and help from there. It starts by getting a simple query, selecting all the tasks from the database. thats stored in a 2 dimentional array of rows an columns. i then start by displaying the due date of the task. thats 3 drop down menus, with number of days (1-31) months (1-12) year (2005-2010). The thing is, this isnt just a normal drop down menu, this is a hidden menu, so when you put it in focus, thats when it appears (see my previous post here). Then it goes on display the client name, project name, and some other miscelaneos data. Finally it starts a new row, but this row is made up of 4 drop down menus, each with 6 items each. Next to each drop down is a text box with the number of hours.
Here is an image of what it looks like

I noticed that it takes longest during the row with the 4 drop down menus. Why do you think this is?
edit: i was looking at xdebug and tryed to install it but i completely lost myself and i dont know what im doing anymore
edit 2: i am 100% sure that the 4 drop down menus are bottlenecking it. When i comment it out, it takes .4 seconds to load the page. ill have to find a way to optimize this now
edit3:
im going to post the code for the problem area. Hopefully someone will notice whats wrong and help me fix it. ask any question about the code, ill try and comment it as best i can
Code: Select all
for ($i = 1; $i <= $cfg['numMaxAdvisors']; $i++) //$cfg['numMaxAdvisors'] is set to 4
{
echo '<select name="advisor'.$i.'[]" onBlur="changed('.$key.')">';
foreach ($blankadvisorlist as $tempkey =>$tempvalue) //$blankadvisorlist is an array (see below)
{
echo '<option value="'.$tempvalue ->mID.'"';
if ($task ->mAdvisors[$i - 1] ->mID == $tempvalue ->mID) //Select the correct advisor
echo " selected";
echo '>'.$tempvalue ->mName.'</option>'; //Display advisor name
}
echo '</select><input type="text" name="hours'.$i.'[]" size=2 value="'.$task ->mNumHours[$i - 1].'" onBlur="changed('.$key.')" > '; //Add the text box next to selection menu
}Code: Select all
$blankadvisorlist Array(
ї0] => "e;"e;
ї1] => "e;Name1"e;
ї2] => "e;Name2"e;
...
ї6] => "e;Name6"e;
)I can't think of anything concrete that would make this faster. It seems though, that you should be able to optimize the foreach loop a bit. It is just looping through a static array and, for the most part, outputing identical code each iteration.
Also, change to
It probably won't give you a noticable difference, but it's better than nothing.
Also, change
Code: Select all
echo " selected";Code: Select all
echo ' selected';Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
even better, change it to:pickle wrote: Also, changetoCode: Select all
echo " selected";Code: Select all
echo ' selected';
Code: Select all
echo ' selected="selected"';