idea? add set_trace_handler() to PHP

idea? add set_trace_handler() to PHP

am 25.12.2009 05:42:21 von Rene Veerman

--00151747856e6aaa2c047b862e2e
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I would like the opinion of the readers of this list on whether or not they
agree on the usefullness of adding some new functions to the core of PHP.

Background Info:

I want more debug-information from my scripts.
And I want to perform lengthy operations in a more robust way.
And I want to monitor such operations in real-time, with points of interest
highlighted, from a webbrowser, using jquery ajax calls.
For instance, when 1000 items are being processed and 10 fail, i want those
listed (with full details) instead of them cancelling the rest of the
operation.

For each lengthy operation, i want to keep track of:
- $operationName, $contextName
- a full trace, with per function the (timing-)stats, arguments, errors
(possibly including notices), and results.
- the ability to monitor the operation flow from a webbrowser (using ajax
calls) in realtime.
- the ability to store such logs (filtered or not) in a database via
adodb.sf.net, or in a file (json / plaintext), or to email them.

I'm considering to release the library i'm building for this as LGPL,
including a viewer.

Problem description:

To enable a full trace i need to call a function that i create, on entry of
any other function, and on exit of such a function.
Obviously adding (even simple, standard) calls to every function i use is
too cumbersome, and i'd miss all the php built-in functions.

The simplest solution to this imo, is to add this to the core of PHP:

$oldTraceHandlerFunctionName = set_trace_handler (
$handlerFunctionName = 'traceHandler',
$functionList = array (
'functionName',
.....
) OR (default:)null=monitor all functions,
);

function traceHandler (
$file = string;fullpath,
$lineNumber = integer,
$functionName = string,
$eventIsStartOfFunction=boolean, // false = being called at exit of
the function
$arguments = array(
'[&]$argumentVariableName' => anyVariable,
.....
),
$localVariables = array(
'localVariableName' => anyVariable,
.....
)
) {
//do something
}

If you have any improvements for this mockup, please post them as reply.


While there are the profiling functions of
http://nl2.php.net/manual/en/function.apd-set-pprof-trace.ph p,
I would nevertheless to propose adding of the new capabilities listed above
here,
for people who don't have enough control over their webserver to install the
requirements of apd-set-pprof-trace.

Also, i haven't looked into it yet, but converting the apd-set-pprof-trace
data to any other format seems to be difficult to do in realtime because it
writes such data to disk.
Turning such data into your own format in realtime will be prone to slowness
&/ errors.

I'll also look at using apd-set-pprof-trace, since none of this is likely to
be implemented soon..
I'll post updates to this thread if i solve that puzzle.

--00151747856e6aaa2c047b862e2e--

Re: idea? add set_trace_handler() to PHP

am 25.12.2009 05:46:11 von Rene Veerman

--00151747830826b123047b863cd6
Content-Type: text/plain; charset=ISO-8859-1

already thought of a small improvement:

function traceHandler (
$file = string;fullpath,
$lineNumber = integer,
$functionName = string,
$eventIsStartOfFunction=boolean, // false = being called at exit of
the function
$arguments = array(
'[&]$argumentVariableName' => anyVariable,
.....
),
$localVariables = array(
'localVariableName' => anyVariable,
.....
),
ADDED : $returnVariable = anyVariable // === null if
$eventIsStartOfFunction===false
) {
//do something
}

--00151747830826b123047b863cd6--

Re: idea? add set_trace_handler() to PHP

am 25.12.2009 11:26:29 von andy-lists

--Apple-Mail-1--38251823
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii

Hi,

Have you taken a look at Xdebug - http://xdebug.org/ ?

=46rom the manual: "Xdebug allows you to log all function calls, =
including parameters and return values to a file in different formats."

Would this do what you need - then your second script could process this =
file?

Regards,
Andy

On 25 Dec 2009, at 04:42, Rene Veerman wrote:

> Hi,
>=20
> I would like the opinion of the readers of this list on whether or not =
they
> agree on the usefullness of adding some new functions to the core of =
PHP.
>=20
> Background Info:
>=20
> I want more debug-information from my scripts.
> And I want to perform lengthy operations in a more robust way.
> And I want to monitor such operations in real-time, with points of =
interest
> highlighted, from a webbrowser, using jquery ajax calls.
> For instance, when 1000 items are being processed and 10 fail, i want =
those
> listed (with full details) instead of them cancelling the rest of the
> operation.
>=20
> For each lengthy operation, i want to keep track of:
> - $operationName, $contextName
> - a full trace, with per function the (timing-)stats, arguments, =
errors
> (possibly including notices), and results.
> - the ability to monitor the operation flow from a webbrowser (using =
ajax
> calls) in realtime.
> - the ability to store such logs (filtered or not) in a database via
> adodb.sf.net, or in a file (json / plaintext), or to email them.
>=20
> I'm considering to release the library i'm building for this as LGPL,
> including a viewer.
>=20
> Problem description:
>=20
> To enable a full trace i need to call a function that i create, on =
entry of
> any other function, and on exit of such a function.
> Obviously adding (even simple, standard) calls to every function i use =
is
> too cumbersome, and i'd miss all the php built-in functions.
>=20
> The simplest solution to this imo, is to add this to the core of PHP:
>=20
> $oldTraceHandlerFunctionName =3D set_trace_handler (
> $handlerFunctionName =3D 'traceHandler',
> $functionList =3D array (
> 'functionName',
> ....
> ) OR (default:)null=3Dmonitor all functions,
> );
>=20
> function traceHandler (
> $file =3D string;fullpath,
> $lineNumber =3D integer,
> $functionName =3D string,
> $eventIsStartOfFunction=3Dboolean, // false =3D being called =
at exit of
> the function
> $arguments =3D array(
> '[&]$argumentVariableName' =3D> anyVariable,
> ....
> ),
> $localVariables =3D array(
> 'localVariableName' =3D> anyVariable,
> ....
> )
> ) {
> //do something
> }
>=20
> If you have any improvements for this mockup, please post them as =
reply.
>=20
>=20
> While there are the profiling functions of
> http://nl2.php.net/manual/en/function.apd-set-pprof-trace.ph p,
> I would nevertheless to propose adding of the new capabilities listed =
above
> here,
> for people who don't have enough control over their webserver to =
install the
> requirements of apd-set-pprof-trace.
>=20
> Also, i haven't looked into it yet, but converting the =
apd-set-pprof-trace
> data to any other format seems to be difficult to do in realtime =
because it
> writes such data to disk.
> Turning such data into your own format in realtime will be prone to =
slowness
> &/ errors.
>=20
> I'll also look at using apd-set-pprof-trace, since none of this is =
likely to
> be implemented soon..
> I'll post updates to this thread if i solve that puzzle.


--Apple-Mail-1--38251823--

Re: idea? add set_trace_handler() to PHP

am 25.12.2009 16:54:14 von Rene Veerman

--001517479428477330047b8f9184
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Dec 25, 2009 at 11:26 AM, Andy Shellam wrote:

> Hi,
>
> Have you taken a look at Xdebug - http://xdebug.org/ ?
>
> From the manual: "Xdebug allows you to log all function calls, including
> parameters and return values to a file in different formats."
>
> Would this do what you need - then your second script could process this
> file?
>
> Regards,
> Andy
>
>
Well, after installing PECL APD, i found that the parameters listed @
http://nl3.php.net/manual/en/function.apd-set-pprof-trace.ph p are incorrect.
Without a guessing game, apd_set_pprof_trace() won't do it's work at all.

So i'll have a look at xdebug between the festivities of these days.. Thanks
for the tip.

I'll probably still have the concurrency problem though (lots of data being
written to disk, read from disk by another thread, and expecting such an
arrangement to keep up with real-time). It's usually a recipe for disaster.

But it'd be soooo cool to fire off multiple "threads" from any php
function(1) and see the functions being called in various threads pop up in
my ajax debugger, with details of any call shown on-mouse-over. Interesting
sub-threads (aka: the ones that produce anomalies) would stay listed,
successfull subthreads would fairly quickly disappear from view.

The one solution i have to avert said disasters is to maintain a pointer
for:
- whatever my own logging format has "absorbed" from the xdebug log file
(for the current operation)
- whatever the browser has read/absorbed from my own logging format.

By timestamping all the entries, i can at least get my ajax debugging wonder
to correctly display all that has happened in very-recent times for my
operation. It'll lag, but i'm hoping i can avert any of the "disasters" that
have plagued me in the past when processing large data sets "through a
disk".

(1)=(by doing $h[$num]=fopen($urlOnMyOwnServer), and then fread($h[$num],
2048) in a loop, processing results when feof($h[$num])===true )

--001517479428477330047b8f9184--