php-general Digest 18 Jan 2011 00:33:04 -0000 Issue 7138
Topics (messages 310817 through 310825):
How to get cpu consumption of a php script
310817 by: Tanoor Dieng
310818 by: [email protected]
310819 by: Tommy Pham
310820 by: Thijs Lensselink
310821 by: Camilo Sperberg
310822 by: Tanoor Dieng
310823 by: Richard Quadling
pcntl_signal() get PID
310824 by: ÐлекÑей ÐаÑленников
PHP Error logging
310825 by: Jimmy Stewpot
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi everybody,
I'm a php developper for a high traffic website. Our web servers run with
lightty?
We have some issues with the cpu consumption of our servers.
The problem is that, we don't know exactly which script consumes so much
cpu.
So, we cant to figure out how much cpu does a php script take.
We have tried 3 methods:
1) Microtime: microtime at the beginning and at the end and make the diff.
The problem with that is that it takes the execution time of the script, but
in our script we make:
- connection to database
- connection to memcache
- connection to session server
All of this is not taken into account, so microtime is not that accurate
2) Shell command: we get the pid of the process executing the script and
make a 'top' on this pid . The problem is that the php-cgi manages many
threads so it's not accurate too.
Is there other methods for dealing with this problem.
Thanks,
best regards,
Tanoor.
--- End Message ---
--- Begin Message ---
I can't think of anything except using top or ps. If you can't guarantee what
process runs what individual script, are you able to just track them all
globally, and check for differences as you start and stop scripts. Perhaps run
certain scripts under different users which should give them their own pid (i
believe, but not tested this) that let's you track them more easily.
Thanks,
Ash
http://www.ashleysheridan.co.uk
----- Reply message -----
From: "Tanoor Dieng" <[email protected]>
Date: Mon, Jan 17, 2011 10:23
Subject: [PHP] How to get cpu consumption of a php script
To: <[email protected]>
Hi everybody,
I'm a php developper for a high traffic website. Our web servers run with
lightty?
We have some issues with the cpu consumption of our servers.
The problem is that, we don't know exactly which script consumes so much
cpu.
So, we cant to figure out how much cpu does a php script take.
We have tried 3 methods:
1) Microtime: microtime at the beginning and at the end and make the diff.
The problem with that is that it takes the execution time of the script, but
in our script we make:
- connection to database
- connection to memcache
- connection to session server
All of this is not taken into account, so microtime is not that accurate
2) Shell command: we get the pid of the process executing the script and
make a 'top' on this pid . The problem is that the php-cgi manages many
threads so it's not accurate too.
Is there other methods for dealing with this problem.
Thanks,
best regards,
Tanoor.
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Monday, January 17, 2011 2:36 AM
> To: Tanoor Dieng; [email protected]
> Subject: Re: [PHP] How to get cpu consumption of a php script
>
> I can't think of anything except using top or ps. If you can't guarantee what
> process runs what individual script, are you able to just track them all
> globally, and check for differences as you start and stop scripts. Perhaps run
> certain scripts under different users which should give them their own pid (i
> believe, but not tested this) that let's you track them more easily.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> ----- Reply message -----
> From: "Tanoor Dieng" <[email protected]>
> Date: Mon, Jan 17, 2011 10:23
> Subject: [PHP] How to get cpu consumption of a php script
> To: <[email protected]>
>
> Hi everybody,
> I'm a php developper for a high traffic website. Our web servers run with
> lightty?
>
> We have some issues with the cpu consumption of our servers.
>
> The problem is that, we don't know exactly which script consumes so much
> cpu.
> So, we cant to figure out how much cpu does a php script take.
>
> We have tried 3 methods:
>
> 1) Microtime: microtime at the beginning and at the end and make the diff.
> The problem with that is that it takes the execution time of the script, but
> in
> our script we make:
> - connection to database
> - connection to memcache
> - connection to session server
>
> All of this is not taken into account, so microtime is not that accurate
>
> 2) Shell command: we get the pid of the process executing the script and
> make a 'top' on this pid . The problem is that the php-cgi manages many
> threads so it's not accurate too.
>
> Is there other methods for dealing with this problem.
>
> Thanks,
> best regards,
>
> Tanoor.
This is untested. Within the same script, you could use [1] or similar and
combine with shellexec ps/top to get what you need. I think this would give
you a better result.
Regards,
Tommy
[1] php.net/function.getmypid
--- End Message ---
--- Begin Message ---
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 01/17/2011 11:23 AM, Tanoor Dieng wrote:
> Hi everybody,
> I'm a php developper for a high traffic website. Our web servers run with
> lightty?
>
> We have some issues with the cpu consumption of our servers.
>
> The problem is that, we don't know exactly which script consumes so much
> cpu.
> So, we cant to figure out how much cpu does a php script take.
>
> We have tried 3 methods:
>
> 1) Microtime: microtime at the beginning and at the end and make the diff.
> The problem with that is that it takes the execution time of the script, but
> in our script we make:
> - connection to database
> - connection to memcache
> - connection to session server
>
> All of this is not taken into account, so microtime is not that accurate
>
> 2) Shell command: we get the pid of the process executing the script and
> make a 'top' on this pid . The problem is that the php-cgi manages many
> threads so it's not accurate too.
>
> Is there other methods for dealing with this problem.
>
> Thanks,
> best regards,
>
> Tanoor.
>
Use something like xdebug & cachegrind to profile the application. This
makes it easy to track down memory and CPU usage.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQIcBAEBAgAGBQJNNB8vAAoJEMffsHAOnubXpRkP/2u0EHXnQR+kkp6pQqM8Gry1
1iFIfqck4Bco3rOYcsX9IK22c/YJZ3RGCMnyZyp+XUAmV615keAtqW/sRgWy/cO9
oaiDHdctdnLeFxmoyRVzR7/FkaeM/bJ7Tj29wnkii8gMbNi8W3zm/RQqBSxoAGig
tJOx+SBi+jqgxfAn18dutRrqDm1lMRNi3wZI8k6Dg2U8i+s/sAjFMVPbNAvLfDzs
uOisnYiJSCdA33zN3IkXD+W9vqVGdHjqF1UABG8srPY/DBUPDjtSrzuHICdQX4SJ
luzgDvnoIVoOE0ntiAPIKba89iXDtIIIlvIX2BkQeGfNIoZWP0/M75siX4drLLI/
6/omgCBOMXkjZ0GMJzdeLPsVjMqagNYKUZfor3KPj0PbpX4RoftWJgvLShHDv74v
nusu8vClDwQNc9eBBZ5Kf7MkXzXVXnFUUO21PSb3WQtX/7eziGrhz8vxYEbR7/zA
XidHE1vfyTr+DNdbkjkYPHyj/s+ZIloNmf/9rjdC8xpEYEevEErUxY+15MXvSZEq
4JmxVUOe3P9ICZSGMf1+BieH9oZRmteFLtMujwHdXVzWVDrCvurM6dwJVdSNZMhT
Ct0PeOwJxJgAtvKL+bOpzd+AMHVEpoWETIYrpXepmCHxbCVCa0fDmxgZ73+32XI8
25mgBHxvMdfINaOjWZJf
=mz+P
-----END PGP SIGNATURE-----
--- End Message ---
--- Begin Message ---
Please take into account that lighttpd does have some random high
cpu-consumption problems, it could be that also. Give nginx a try instead.
Also: microtime by itself isn't enough, sum time() to it because if a script
lasts more than 1 second you can end up with negative total time, microtime
doesn't have a seconds counter, only microseconds.
Are you using a cms? Have you tried deactivating some plugins?
Sent from my iPhone
On 17-01-2011, at 7:23, Tanoor Dieng <[email protected]> wrote:
> Hi everybody,
> I'm a php developper for a high traffic website. Our web servers run with
> lightty?
>
> We have some issues with the cpu consumption of our servers.
>
> The problem is that, we don't know exactly which script consumes so much
> cpu.
> So, we cant to figure out how much cpu does a php script take.
>
> We have tried 3 methods:
>
> 1) Microtime: microtime at the beginning and at the end and make the diff.
> The problem with that is that it takes the execution time of the script, but
> in our script we make:
> - connection to database
> - connection to memcache
> - connection to session server
>
> All of this is not taken into account, so microtime is not that accurate
>
> 2) Shell command: we get the pid of the process executing the script and
> make a 'top' on this pid . The problem is that the php-cgi manages many
> threads so it's not accurate too.
>
> Is there other methods for dealing with this problem.
>
> Thanks,
> best regards,
>
> Tanoor.
--- End Message ---
--- Begin Message ---
Hi thanks, for xdebug, we'll take al look at it.
On Mon, Jan 17, 2011 at 11:51 AM, Thijs Lensselink <[email protected]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 01/17/2011 11:23 AM, Tanoor Dieng wrote:
> > Hi everybody,
> > I'm a php developper for a high traffic website. Our web servers run with
> > lightty?
> >
> > We have some issues with the cpu consumption of our servers.
> >
> > The problem is that, we don't know exactly which script consumes so much
> > cpu.
> > So, we cant to figure out how much cpu does a php script take.
> >
> > We have tried 3 methods:
> >
> > 1) Microtime: microtime at the beginning and at the end and make the
> diff.
> > The problem with that is that it takes the execution time of the script,
> but
> > in our script we make:
> > - connection to database
> > - connection to memcache
> > - connection to session server
> >
> > All of this is not taken into account, so microtime is not that accurate
> >
> > 2) Shell command: we get the pid of the process executing the script and
> > make a 'top' on this pid . The problem is that the php-cgi manages many
> > threads so it's not accurate too.
> >
> > Is there other methods for dealing with this problem.
> >
> > Thanks,
> > best regards,
> >
> > Tanoor.
> >
>
> Use something like xdebug & cachegrind to profile the application. This
> makes it easy to track down memory and CPU usage.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iQIcBAEBAgAGBQJNNB8vAAoJEMffsHAOnubXpRkP/2u0EHXnQR+kkp6pQqM8Gry1
> 1iFIfqck4Bco3rOYcsX9IK22c/YJZ3RGCMnyZyp+XUAmV615keAtqW/sRgWy/cO9
> oaiDHdctdnLeFxmoyRVzR7/FkaeM/bJ7Tj29wnkii8gMbNi8W3zm/RQqBSxoAGig
> tJOx+SBi+jqgxfAn18dutRrqDm1lMRNi3wZI8k6Dg2U8i+s/sAjFMVPbNAvLfDzs
> uOisnYiJSCdA33zN3IkXD+W9vqVGdHjqF1UABG8srPY/DBUPDjtSrzuHICdQX4SJ
> luzgDvnoIVoOE0ntiAPIKba89iXDtIIIlvIX2BkQeGfNIoZWP0/M75siX4drLLI/
> 6/omgCBOMXkjZ0GMJzdeLPsVjMqagNYKUZfor3KPj0PbpX4RoftWJgvLShHDv74v
> nusu8vClDwQNc9eBBZ5Kf7MkXzXVXnFUUO21PSb3WQtX/7eziGrhz8vxYEbR7/zA
> XidHE1vfyTr+DNdbkjkYPHyj/s+ZIloNmf/9rjdC8xpEYEevEErUxY+15MXvSZEq
> 4JmxVUOe3P9ICZSGMf1+BieH9oZRmteFLtMujwHdXVzWVDrCvurM6dwJVdSNZMhT
> Ct0PeOwJxJgAtvKL+bOpzd+AMHVEpoWETIYrpXepmCHxbCVCa0fDmxgZ73+32XI8
> 25mgBHxvMdfINaOjWZJf
> =mz+P
> -----END PGP SIGNATURE-----
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On 17 January 2011 10:58, Camilo Sperberg <[email protected]> wrote:
> Please take into account that lighttpd does have some random high
> cpu-consumption problems, it could be that also. Give nginx a try instead.
>
> Also: microtime by itself isn't enough, sum time() to it because if a script
> lasts more than 1 second you can end up with negative total time, microtime
> doesn't have a seconds counter, only microseconds.
http://www.php.net/manual/en/function.microtime.php : Return current
Unix timestamp with microseconds
Hmm. I'm guessing it does.
[2011/01/17 11:16:06] [Z:\] [\\richardquadling\scratch$ ] >php -r
"echo microtime(true);"
1295263156.1895
Oh yeah!
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
Hi everyone!
My question is:howto getPIDtreadchildto send a signalhandlerinstalled
inpcntl_signal()?
I apologizeformyEnglish,I'm fromRussia.
Thanks.
--- End Message ---
--- Begin Message ---
Hello,
I currently have a strange issue where we are seeing 'random errors' being
displayed to end users. What I find most interesting is that in the php.ini
file we have the following error settings.
error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
track_errors = Off
I thought that if we had dislay_errors = Off then end users should never see
errors displayed on the web page. However at apparently random times we do
still see errors being reported, its not consistent at all. To give a better
idea of the problem we have 8 web servers, they all run an identical copy of
the site which is stored on a common netapp nfs filer. At apparently random
times we see that 1 out of 8 servers will reported strange errors like 'use of
undefined constant' or 'Undefined variable'. What's most strange about these
errors is that if the code was faulty wouldn't we expect to see the errors on
all web servers? and secondly wouldn't we expect to see the errors constantly
rather than at apparently random intervals?
The php.ini files have a modify time of mid 2010 and yet this problem has only
started in the last few weeks. Has anyone else experienced similar problems in
the past and if so what was the root cause?
Regards,
Jimmy
--- End Message ---