php-general Digest 28 Mar 2009 17:06:21 -0000 Issue 6037

Topics (messages 290783 through 290793):

Re: flushing AJAX scripts
        290783 by: jim white
        290787 by: Andrea Giammarchi

Re: Sort a multi-dimensional array on a certain key followed by another key
        290784 by: Jim Lucas

foreach and form submission.
        290785 by: Angus Mann
        290786 by: Ashley Sheridan
        290790 by: Virgilio Quilario

Re: PHPizabi - Applying php in TPL (smarty template engine)
        290788 by: Virgilio Quilario

Calling function on the same line?
        290789 by: דניאל דנון
        290791 by: Andrea Giammarchi
        290793 by: Virgilio Quilario

Re: SESSION values show up days later!
        290792 by: tedd

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 --- Well, the point was that I had tried the first way, submitting one AJAX request and waiting for it to finish and it was timing out, probably on my firewall which it shouldn't have - but it did. The reports can take 10 seconds or 10 minutes to create. Doing it this way I can still load the report even if the original request shuts down after 3-4 minutes.

Jim

Andrea Giammarchi wrote:
Sorry Jim, I meant Jim when I wrote Kim ... and Phico: http://webreflection.blogspot.com/2008/04/phomet-changes-name-so-welcome-phico.html

Regards

From: [email protected]
To: [email protected]
Date: Fri, 27 Mar 2009 15:55:28 +0100
Subject: RE: [PHP] flushing AJAX scripts


Sorry, Kim, but why on earth you are polling with a second request to know when 
the first one has finished?
I mean, when the first request inserts data in the database that's it, you'll 
manage the end of the request.

$A --->  do stuff; do stuff; do stuff; report ready;
$B ---> report ready?
$B ---> report ready?
$B ---> report ready?
$B ---> report ready?
report ready; ---> notification to A
$B ---> report ready;

the report ready, if it is when $A request has been finished, will be in $A, 
the polling via $B is absolutely useless, imo.

There is no timeout from Ajax, it simply keep waiting, but obviously if your 
PHP has max_execution_time 30 seconds and the script execution takes more than 
30 seconds there's no polling that could save you.

The same if the user closes the browser, connection lost, bye bye response.

To have a notice, you need Comet, try out Phico but still, a page that requires 
that much is not suitable for the web. Report creation should be a cronjob in a 
separed thread if it is that stressful.

Regards

Date: Fri, 27 Mar 2009 10:47:10 -0400
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: RE: [PHP] flushing AJAX scripts

My page submits the AJAX request to complete a report that takes some time, and upon completion stores results in a database. A second AJAX request polls every 5 seconds and queries the database if the report is ready. This hopefully will get around any timeout problems I am having with a long running request, and seems to be working. It looks like I can accept the default behavior for now. I don't depend on getting a response from the original request, but is there a point where the AJAX response script will be stopped either by Apache or PHP before it can insert into the database?

Jim
_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx


--
James (Jim) B. White
tel: (919)-380-9615
homepage: http://jimserver.net/
--- End Message ---
--- Begin Message ---
As I said if the client abort or close the connection, PHP does not finish its 
execution, it simply exits from the script.

If you run this code and you close the browser before 10 seconds the file will 
never be created, for example.

<?php
function write($stuff){
    echo    $stuff, PHP_EOL."<br />", ob_get_clean();
    @ob_flush();
    @flush();
};
$seconds = 10;
ob_start();
while($seconds){
    write('I should do something in '.($seconds--).' seconds');
    sleep(1);
}
$fp = fopen('test.txt', 'wb');
fwrite($fp, gmdate('Y-m-d H:i:s'));
fclose($fp);
write('Finished!');
?>

but, obviously, if you launch a query via PHP and PHP is killed, MySQL will go 
on performing the query until it has been fully executed but if PHP would like 
to do something else after that query and again, the client leave the page, PHP 
will never perform that operation.

So, unless you are not creating a flagged report in one shoot and your system 
is clever enough to understand what's going on in a secure way, I still suggest 
delayed, crontabbed or extra threads for this task which does not suite/scale 
in a webpage.
In my company we are using multi threading tasks with real status able to 
constantly monitor the situation but we are in C# over SQLServer.
I did something similar in PHP and Ajax and MySQL in the old company but trust 
me, it is not simple if you want to be consistent.

Regards.



> Date: Sat, 28 Mar 2009 00:45:27 -0400
> From: [email protected]
> To: [email protected]
> Subject: Re: RE: [PHP] flushing AJAX scripts
> 
> Well, the point was that I had tried the first way, submitting one AJAX 
> request and waiting for it to finish and it was timing out, probably on 
> my firewall which it shouldn't have - but it did. The reports can take 
> 10 seconds or 10 minutes to create. Doing it this way I can still load 
> the report even if the original request shuts down after 3-4 minutes.
> 
> Jim
> 
> Andrea Giammarchi wrote:
> > Sorry Jim, I meant Jim when I wrote Kim ... and 
> > Phico: 
> > http://webreflection.blogspot.com/2008/04/phomet-changes-name-so-welcome-phico.html
> >
> > Regards
> >
> >   
> >> From: [email protected]
> >> To: [email protected]
> >> Date: Fri, 27 Mar 2009 15:55:28 +0100
> >> Subject: RE: [PHP] flushing AJAX scripts
> >>
> >>
> >> Sorry, Kim, but why on earth you are polling with a second request to know 
> >> when the first one has finished?
> >> I mean, when the first request inserts data in the database that's it, 
> >> you'll manage the end of the request.
> >>
> >> $A --->  do stuff; do stuff; do stuff; report ready;
> >> $B ---> report ready?
> >> $B ---> report ready?
> >> $B ---> report ready?
> >> $B ---> report ready?
> >> report ready; ---> notification to A
> >> $B ---> report ready;
> >>
> >> the report ready, if it is when $A request has been finished, will be in 
> >> $A, the polling via $B is absolutely useless, imo.
> >>
> >> There is no timeout from Ajax, it simply keep waiting, but obviously if 
> >> your PHP has max_execution_time 30 seconds and the script execution takes 
> >> more than 30 seconds there's no polling that could save you.
> >>
> >> The same if the user closes the browser, connection lost, bye bye response.
> >>
> >> To have a notice, you need Comet, try out Phico but still, a page that 
> >> requires that much is not suitable for the web. Report creation should be 
> >> a cronjob in a separed thread if it is that stressful.
> >>
> >> Regards
> >>
> >>     
> >>> Date: Fri, 27 Mar 2009 10:47:10 -0400
> >>> From: [email protected]
> >>> To: [email protected]
> >>> CC: [email protected]
> >>> Subject: Re: RE: [PHP] flushing AJAX scripts
> >>>
> >>> My page submits the AJAX request to complete a report that takes some 
> >>> time, and upon completion stores results in a database. A second AJAX 
> >>> request polls every 5 seconds and queries the database if the report is 
> >>> ready. This hopefully will get around any timeout problems I am having 
> >>> with a long running request, and seems to be working. It looks like I 
> >>> can accept the default behavior for now. I don't depend on getting a 
> >>> response from the original request, but is there a point where the AJAX 
> >>> response script will be stopped either by Apache or PHP before it can 
> >>> insert into the database?
> >>>
> >>> Jim
> >>>       
> >> _________________________________________________________________
> >> News, entertainment and everything you care about at Live.com. Get it now!
> >> http://www.live.com/getstarted.aspx
> >>     
> >
> > _________________________________________________________________
> > Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
> >
> > http://www.microsoft.com/windows/windowslive/products/photos.aspx
> >   
> 
> 
> -- 
> James (Jim) B. White
> tel: (919)-380-9615
> homepage: http://jimserver.net/ 
> 

_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/

--- End Message ---
--- Begin Message ---
TS wrote:
Ok so, I have an array

[0(index)][1st key][2nd key]

Basically I don't care about the index. As a matter of fact I'd prefer it
reset to still be in order afterwards.

However, I need to sort the 1st key and keep correlation w the second key.
Then sort on the second key.

I have video volumes and scenes like
[0][110][1]
[1][110][3]
[2][110][2]
[3][110][4]

Any help would be much appreciated.



<plaintext><?php

function recursive_ksort(&$ar) {
        if ( is_array($ar) ) {
                ksort($ar);
                foreach ( $ar AS $k => $v ) {
                        if ( is_array($v) ) {
                                recursive_ksort($v);
                                $ar[$k] = $v;
                        }
                }
        } else {
                echo 'ERROR: recursive_ksort() expect the first argument to be 
an array()';
        }
        return false;
}

$d[0][110][1] = '01101';
$d[0][110][2] = '01102';
$d[0][110][3] = '01103';
$d[1][113][3] = '11103';
$d[1][115][1] = '11101';
$d[1][114][3] = '11103';
$d[2][110][2] = '21102';
$d[3][114][2] = '31102';
$d[2][110][1] = '21101';
$d[3][110][3] = '31103';
$d[2][110][4] = '21104';
$d[3][111][4] = '31104';

recursive_ksort($d);

print_r($d);

?>

Seems to work for me.  Give it a run and let us know...


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Hi all.

I'm writing a script that accepts several different forms with different 
content. Depending on what data is sent with the form the script will do one or 
the other think.

Before the form data is processed I'd like to scrub it of HTML tags.

I can do this manually as below but the form may have dozens of items of data 
so I'd like to automate it.

$_POST['name'] = strip_tags($_POST['name']);
$_POST['address'] = strip_tags($_POST['address']);
$_POST['phone'] = strip_tags($_POST['phone']);

I saw a few lines of code once that used "foreach"  on the $_POST array 
elements and it did not seem to matter how many or what names the elements had.

Conceptually like this

foreach ($_POST - element) {
    $_POST-element = strip_tags($_POST-element)
}

Any ideas please ?

Thanks.

--- End Message ---
--- Begin Message ---
On Sat, 2009-03-28 at 18:28 +1000, Angus Mann wrote:
> Hi all.
> 
> I'm writing a script that accepts several different forms with different 
> content. Depending on what data is sent with the form the script will do one 
> or the other think.
> 
> Before the form data is processed I'd like to scrub it of HTML tags.
> 
> I can do this manually as below but the form may have dozens of items of data 
> so I'd like to automate it.
> 
> $_POST['name'] = strip_tags($_POST['name']);
> $_POST['address'] = strip_tags($_POST['address']);
> $_POST['phone'] = strip_tags($_POST['phone']);
> 
> I saw a few lines of code once that used "foreach"  on the $_POST array 
> elements and it did not seem to matter how many or what names the elements 
> had.
> 
> Conceptually like this
> 
> foreach ($_POST - element) {
>     $_POST-element = strip_tags($_POST-element)
> }
> 
> Any ideas please ?
> 
> Thanks.
I'd do something like this, so as to preserve the original post data
array:

$data = Array();
foreach($_POST as $key => $value)
{
    $data[$key] = strip_tags($value);
}

Note that strip_tags() will not be able to decently clean up messy code
(i.e. code where the opening or closing tags themselves aren't formed
properly)


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
> Hi all.
>
> I'm writing a script that accepts several different forms with different 
> content. Depending on what data is sent with the form the script will do one 
> or the other think.
>
> Before the form data is processed I'd like to scrub it of HTML tags.
>
> I can do this manually as below but the form may have dozens of items of data 
> so I'd like to automate it.
>
> $_POST['name'] = strip_tags($_POST['name']);
> $_POST['address'] = strip_tags($_POST['address']);
> $_POST['phone'] = strip_tags($_POST['phone']);
>
> I saw a few lines of code once that used "foreach"  on the $_POST array 
> elements and it did not seem to matter how many or what names the elements 
> had.
>
> Conceptually like this
>
> foreach ($_POST - element) {
>    $_POST-element = strip_tags($_POST-element)
> }
>
> Any ideas please ?
>
> Thanks.
>

here,

foreach ($_POST as $key => $value) {
  $_POST[$key] = strip_tags($value);
}

good luck.

virgil
http://www.jampmark.com

--- End Message ---
--- Begin Message ---
> Well well I forgot to install Smarty, but show the message. Ididn't modify
> Smasrty.class.php. And index.tpl in libs directpory don't exist only the
> file in root.
>
> Anybody Can save me? I'm X confuss. All is new for me.
>
>  Warning: Smarty error: unable to read resource: "index.tpl" in
> /home/lucianofelli/www/teste/smarty/libs/Smarty.class.php on line 1092
>

smarty wasn't able to read your tpl.
please see this page about troubleshooting smarty tpl
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=4500

virgil
http://www.jampmark.com

--- End Message ---
--- Begin Message ---
Is there any way to do something like:

<?php
("str_replace")("a", "b", "aaa");
?>

?

One of the problems that I must keep "str_replace" on the same line...The
only solution I see is call_user_func, but I would like to know if you guys
might have a clue =]
Tried looking on the manual, sadly didn't found anything

Thanks, Daniel

--- End Message ---
--- Begin Message ---
I miss the utility to do stuff like that ... seriously ... but in any case:

<?php
echo ($f = 'str_replace') ? $f("a", "b", "aaa") : null;
?>

where echo is optional.

Regards


> Date: Sat, 28 Mar 2009 15:26:18 +0300
> From: [email protected]
> To: [email protected]
> Subject: [PHP] Calling function on the same line?
> 
> Is there any way to do something like:
> 
> <?php
> ("str_replace")("a", "b", "aaa");
> ?>
> 
> ?
> 
> One of the problems that I must keep "str_replace" on the same line...The
> only solution I see is call_user_func, but I would like to know if you guys
> might have a clue =]
> Tried looking on the manual, sadly didn't found anything
> 
> Thanks, Daniel

_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/

--- End Message ---
--- Begin Message ---
>
> I miss the utility to do stuff like that ... seriously ... but in any case:
>
> <?php
> echo ($f = 'str_replace') ? $f("a", "b", "aaa") : null;
> ?>
>
> where echo is optional.
>
> Regards

you mean this
<?= ($f = 'str_replace') ? $f("a","b","aaa") : null; ?>

virgil
http://www.jampmark.com

--- End Message ---
--- Begin Message ---
At 2:39 PM -0700 3/27/09, Mary Anderson wrote:
Hi all,
I use session variables to store values from one page to another on my website. Alas, sometimes, but not always, the values persist from one invocation of the script to another! Just how, exactly, do I make them go away when a user exits the program? I assume my users will not always be logging out explicitly.
   Thanks.
    maryfran


maryfran:

I don't know if this will help, but this a "solution" I used once.

<?php session_start();

// destroy all session data including login -- the user can login again to make sure everything is OK

// bye bye cookie
if (isset($_COOKIE[session_name()]))
   {
   setcookie(session_name(), '', time()-42000, '/');
   }

 // and finally
session_destroy();

header("location:http://<where I wanted to send the user>");
exit();
?>

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---

Reply via email to