php-general Digest 25 Dec 2009 10:26:40 -0000 Issue 6505
Topics (messages 300678 through 300682):
Re: strtotime - assumptions about default formatting of dates
300678 by: Angus Mann
Re: Tracking file download progress
300679 by: kranthi
idea? add set_trace_handler() to PHP
300680 by: Rene Veerman
300681 by: Rene Veerman
300682 by: Andy Shellam
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
I wrote a little AJAX gadget which sent the string typed to a PHP backend
which parsed it using strtotime and then formatting it out again as
something unamiguous (like 2 January 2009). Then every time the date entry
field is changed by the user (with an onKeyUp event), this AJAX call is
triggered and displays the unambiguous form next to the input box, so
users can see how their entry is being interpreted.
Of course, there's some overhead in the AJAX calls, and it requires
JavaScript.
If you wanted to do without JavaScript you could do a similar parse-format
sequence when the form is submitted and show a confirmation page with your
server's interpretation of the date.
Cheers
Pete
I took this idea and wrote an ajax so that on keyup or blur, the entry is
sent to PHP which puts it into strtotime() and if a valid result comes out,
formats it something like "Wed January 23, 2008 6:23pm". If the result is
invalid, it outputs an "Invalid" message. This is then displayed in a span
next to the textbox.
So as the user types they can see if what they entered is valid, and also
see how the date/time will be interpreted. Works beautifully, and makes the
form very usable.
For what it's worth, here is the code:
The PHP ajax (called judgedatetime.php:
-----------
$inp=$_REQUEST['a'];
$a=strtotime($inp);
if ($a < 1200103200){
$b="Invalid";
} else {
$b=date("D M j, Y g:ia",$a);
}
echo $b;
?>
The Javascript
---------------
function assessdtime(dTime,putHere){
AjaxRequest.get({'url':'ajax/judgedatetime.php',
'parameters':{'a':dTime},
'onSuccess':function(req){
document.getElementById(putHere).innerHTML=req.responseText;
}
})}
And HTML embedded in the page..
-----------------------------------
<input type="text" size="14" id="start" name="start"
onkeyup="assessdtime(this.value,'startreport');"
onblur="assessdtime(this.value,'startreport');" />
<span id="startreport">Enter a date and time</span>
--- End Message ---
--- Begin Message ---
Just out of curiosity. Can you please tell me how you initiated the download?
--- End Message ---
--- Begin Message ---
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.php,
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.
--- End Message ---
--- Begin Message ---
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
}
--- End Message ---
--- Begin Message ---
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
On 25 Dec 2009, at 04:42, Rene Veerman wrote:
> 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.php,
> 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.
--- End Message ---