Solved

PHP Script Performance Monitoring

Posted on 2009-05-04
13
306 Views
Last Modified: 2013-12-12
I am looking for a way to compile a performance log of *all* php scripts on my site.  It is easy to compile informaiton like execution time with some scripting, but I'd like to gather additional info like average CPU for a particular script.

I am looking on my server at top and see particular scripts being executed and this shows CPU/Memory usage.

If I could have something log what I see in top just prior to the process ending (or so that it tracks the max value for memory and average for CPU?) I thinK I would be happy.

I am trying to find under-performing scripts in my site to enhance perfomance and have no really good tools for helping me find unexpected problem spots.

I don't own the server (sadly) so anything requiring root, etc. may not work for me.  I was hoping there was something in the PHP engine itself that I could leverage that tracks and provides this data.  
0
Comment
Question by:trippy1976
  • 6
  • 2
  • 2
  • +1
13 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24305970
trippy1976: This is not all that recent, but it may be useful as a starting point:
http://www.linuxjournal.com/article/7213

And God Bless Google...
http://www.google.com/search?hl=en&q=php%2Bscript%2Bperformance

Whenever there are performance issues, the problem is almost always in the I/O subsystem and in web hosting that usually means the data base.  A good place to start is to look at all the DB queries.  Some good questions to consider:

Are you doing a SELECT with WHERE or ORDER BY clauses that refer to unindexed fields?
Are you doing a SELECT * when you do not really need all the fields?
Do you have a BLOB (or similar) stored in the DB when it would really work better in the file system?
Do you have a LIMIT clause on SELECT statements?
Can you combine queries and make fewer calls to mysql_query()?
You can (and should) use EXPLAIN on all your queries to see what MySQL is doing.

Anyway, that's just a few thoughts.  Best regards, ~Ray
0
 
LVL 4

Author Comment

by:trippy1976
ID: 24314860
I googled all day.  The information you posted is good, but the trouble is with my host I don't have root access and most of these things aren't available.

I'm going to look into doing something "rough" like top logging and try to get a view of the trouble spots with that, but we will see...

Good info and good tips on the sql queries.  The only one jumps out at me is the limit by clause comment.  I have a table with 3600+ records.  The user view is a paginated 30-per-page gallery view of that data.  I currently use a query to "flip through" the pages with a limit statement.

Is there a better way?  At least query-wise?

If I can impose on you for a few thoughts on this I would appreciate it.  I think your info is what I expected for the Q and I appreciate hte time.  Points will be credited soon.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24315822
Regarding this: "... use a query to "flip through" the pages..." - Yes, I think that is the right approach.   Quite likely that the MySQL server will cache this stuff after its initial selection and subsequent selects will be faster (even if the actual rows were not in the initial recordset.

I'll be glad to let you pick my brain.  

Best, ~Ray
0
 
LVL 7

Expert Comment

by:ycTIN
ID: 24323820
you can add some monitoring code into you page, logging the $time to database or file
$time / 1 * 100% = One CPU %
<?php

$time_start = microtime(true);
 

// main program start
 

usleep(10000);// Sleep for a while
 

// main program end
 

$time_end = microtime(true);

$time = $time_end - $time_start;
 

echo "Did nothing in $time seconds\n";

?> 

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24564047
I'm sure I answered at least part of the Q.  Never did hear back about the other parts, obviously.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24728862
@angelIII: I think this should not be a deletion.

To quote the poster at #24314860, "I think your info is what I expected for the Q and I appreciate hte [sic] time.  Points will be credited soon."

Thanks for your consideration,
~Ray
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24728888
Ray,

  yes, that was considered.
  however, my decision was rather based on:
  >The information you posted is good, but the trouble is with my host I don't have root access and most of these things aren't available.

  and I think the only real suggestion would have been to change each script individually to store the execution time in a database ...
 
  your suggestions were either too general, or steps for the the actual troubleshooting of a concrete problem, rather than to identify the scripts/pages that actually have most problems.

a3
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24728894
OK, not a big issue for me.  Our OP said both of those things in the same post, so I can see it either way.  But I can't see what your logic is until after I post an objection.  Sorry if it was an unnecessary exercise. ~Ray
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24728933
>Sorry if it was an unnecessary exercise. ~Ray
not unnecessary. I have the trouble in the CV tool that I cannot give additional comments, unless I open the question and post a additional comment.
which is usually not needed.
I understand that these questions are frustrating for us experts.
a3
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24728939
10-4.  Best regards, ~Ray
0
 
LVL 4

Author Closing Comment

by:trippy1976
ID: 31577655
Thank you for the input, it is a daunting topic and the response did little to whittle down where I should spend my time.  As a part-time developer, I have yet to find the time to delve as deeply into the topic as I need in order to even decide if this is a solution.  I apologize for the delay, but some people in the EE community are not full timers and need time to digest complicated subjects.

I have no idea if this is a solution, but rather than be labeled as an "irresponsible EE member" I'll just post the points.  Sheesh.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now