php-general Digest 23 Jul 2005 18:57:06 -0000 Issue 3584

Topics (messages 219248 through 219255):

Re: On register_shutdown_function: What might be the problem?
        219248 by: Rasmus Lerdorf

speed - PHP/MYSQL
        219249 by: balwant singh
        219250 by: Jasper Bryant-Greene

Re: Rasmus' 30 second AJAX Tutorial - [was Re: [PHP] AJAX & PHP]
        219251 by: Chris Boget
        219254 by: Rasmus Lerdorf

PEAR DB issue
        219252 by: Chris Boget

Re: System specific information gathering
        219253 by: André Medeiros

Re: AJAX & PHP
        219255 by: Brian V Bonini

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
If you don't flush some output after setting the header() then the
headers won't go out until the end of the request.  So do something like:

ignore_user_abort(true);
header("Location: http://whatever";);
echo "foo\n"; flush();

Then whatever comes after this should run and the browser is long gone.

-Rasmus


Liang ZHONG wrote:
> I think I did not express myself clearly.
> 
> What I want is to be able to redirect user an existing page (let them
> get it immediately), and to close the connection actively, NOT passively
> by user abort, at last, to run the function in background.
> 
> But the redirecting using function header() with location has a problem
> that header() always does return the page to user after the entire
> program, including registered showdown function finish running, which is
> against the will. I put a time consuming task into a function that
> registered to be a shutdown function and hoping it runs after the user
> has got the redirected page and the connection has been closed. But
> experiements (using browsers, curl command line tool as well as
> perl::LWP code) show that the user got the redirected page only after
> the shutdown function finished, which is against the description of
> register_shutdown_function at php website.
> 
> It seems only header() function use to redirect page has this problem
> (not executed until register_shutdown_function finished) while other
> functions like print()/echo(), exec() have not.
> 
> The code looks like:
> ---------------------------------------------------------------------------------------------
> 
> <?php
> set_time_limit(1);
> 
> function f(){
> set_time_limit(20);
> $count=50000000;
> for($i=0; $i<$count; $i++){ }
> echo "end";
> exec("touch /home/.nappy/liang/liang.ns2user.info/php/aaa");
> }
> 
> register_shutdown_function('f');
> 
> header("Content-type: text/plain");
> header("Location: y.html");
> ?>
> ---------------------------------------------------------------------------------------------
> 
> 
> http client who sends the request to the php program will only get the
> page back as response after function f finsihes (file aaa created).
> Changing the $count will make a lot difference.
> 
> My BIGGEST question is:
> How to make user get the redirect page immediately after the header() is
> called, and not until function f() ends, while making sure that the
> function f() will finally fully (and might slowly) execute?
> 
> Thank you very much for kindly replying.
> 
> With high respect,
> 
> Liang
> 
> 
>>
>> Liang ZHONG wrote:
>> > My Question is:
>> > What is the correct way to keep the function running after I
>> redirect an
>> > existing page to http client (which I want the client get immediately)
>> > and then immediately close the connection?
>>
>> ignore_user_abort(true);
>>
>> -Rasmus
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
> 

--- End Message ---
--- Begin Message ---
Hi,

I have made a webpage in php which retrieves the data from a huge MYSQL tables as below:-

$i=0;
while ($i<=23)
{
select a, b from table where hour(time)=$i and date='' order by desc time limit 1;
$i++;
}

then i substract the current hour output from the last hour output for calcuating the output in that hour through PHP code and then display it.

But my problem is that this page takes approx. 90 seconds or more for loading even when i refresh the page, it is taking the same time.

I have done indexing on that table, tune the php and apache but it is still taking same time.

I have other tables also when PHP is doing more calculatios but those pages are not taking so much time they load in 5 sec. or so.

Is there anything needs to be done more, please advise.

--
With Best Wishes

Balwant Singh

--- End Message ---
--- Begin Message ---
balwant singh wrote:
Hi,

I have made a webpage in php which retrieves the data from a huge MYSQL tables as below:-

$i=0;
while ($i<=23)
{
select a, b from table where hour(time)=$i and date='' order by desc time limit 1;
$i++;
}

then i substract the current hour output from the last hour output for calcuating the output in that hour through PHP code and then display it.

But my problem is that this page takes approx. 90 seconds or more for loading even when i refresh the page, it is taking the same time.

I have done indexing on that table, tune the php and apache but it is still taking same time.

I have other tables also when PHP is doing more calculatios but those pages are not taking so much time they load in 5 sec. or so.

Is there anything needs to be done more, please advise.

Don't loop through in PHP and execute the query 23 times. Instead, execute the query once (without the "hour(time)=$1 and " and the "limit 1", and use a while($row = mysql_fetch_assoc($result)) { } type function to get all 23 rows. That will be much faster.

By the way, that should probably be "order by time desc" not "order by desc time".

Jasper

--- End Message ---
--- Begin Message ---
> function sndReq(action) {
>     http.open('get', 'rpc.php?action='+action);
>     http.onreadystatechange = handleResponse;
>     http.send(null);
> }

So with AJAX, the data gets sent back to the browser using GET?
Is there any way you can do it using POST?

thnx,
Chris

--- End Message ---
--- Begin Message ---
Chris Boget wrote:
>>function sndReq(action) {
>>    http.open('get', 'rpc.php?action='+action);
>>    http.onreadystatechange = handleResponse;
>>    http.send(null);
>>}
> 
> 
> So with AJAX, the data gets sent back to the browser using GET?
> Is there any way you can do it using POST?

The prototype for the http.open method looks like this:

open("method","URL",async,"uname","pswd")

So to do a POST request instead, just use 'post' instead of 'get' in the
first argument.  Then put the url encoded post data in the http.send() call.

-Rasmus

--- End Message ---
--- Begin Message ---
I'm using PEAR::DB to connect to a MS SQL Server 2000.
I'm attempting to run the following query:

SELECT * FROM myTable FOR XML AUTO, ELEMENTS

When I run the above query using the Query Analyzer, I get back
the results as expected.  However, when I try to run the same query
using PEAR, I get the following error:

[nativecode=4004 - Unicode data in a Unicode-only collation or 
ntext data cannot be sent to clients using DB-Library (such as ISQL) 
or ODBC version 3.7 or earlier.]

and I'm not sure why.  I've googled the error and see that alot of
other people are getting the same error (though, it doesn't seem
that they are necessarily using PEAR).  From what I can tell, it is
a client error and not a server error.  So my questions are 1) is
there something wrong with PEAR and 2) if so, is there a fix in
the works?  Does anyone know?  But that aside, has anyone else
come up against this issue and found a workaround using PEAR?

thnx,
Chris

--- End Message ---
--- Begin Message ---
First of all, you want to have the two values in seperate variables.
After reading the contents from the file, do something like:

-----------------------------------------8<---------------------------------------------
function parseUptimeSeconds( $seconds ) {
    $resultArray = Array( 'weeks' => 0, 'days' => 0, 'hours' => 0,
'minutes' => 0, 'seconds' =>  0);

    // check weeks
    while( $seconds > 604800 ) {
        $resultArray['weeks']++;
        $seconds -= 604800;
    }

    // check days
    while( $seconds > 86400) {
        $resultArray['days']++;
        $seconds -= 86400;
    }

    // check hours
    while( $seconds > 3600) {
        $resultArray['hours']++;
        $seconds -= 3600;
    }

    // check minutes
    while( $seconds > 60) {
        $resultArray['minutes']++;
        $seconds -= 60;
    }

    $resultArray['seconds'] = $seconds;

    return( $resultArray );
}

// separate both values
list( $uptimeSeconds, $idleSeconds ) = explode( ' ', $lineReadFromFile );
$uptimeElements = parseUptimeSeconds( $uptimeSeconds );
$idleElements = parseUptimeSeconds( $idleSeconds );
-----------------------------------------8<---------------------------------------------

I know there might be a more efficient way of doing this, like using
the modulus operator, but hey :)

On 7/23/05, Ramil Sagum <[EMAIL PROTECTED]> wrote:
> On 7/23/05, Vidyut Luther <[EMAIL PROTECTED]> wrote:
> > Ok,
> >   If I use the file_get_contents.. how do I actually parse the
> > contents on /proc/uptime
> > cat /proc/uptime
> > 1400293.13 1317047.64
> 
> 
> The first number is the total uptime in seconds, the second number is
> the total idle time.
> 
> --
> ----
> 
> 
> 
> ramil
> http://ramil.sagum.net/
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
On Thu, 2005-07-21 at 08:23, Marco Tabini wrote:
> We had a webcast on PHP and Ajax a while back--the recordings are still
> available for free at http://blogs.phparch.com/mt/index.php?p=49.

Nice, totally crashes Firefox in Linux.


-- 

s/:-[(/]/:-)/g


Brian        GnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
======================================================================
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

--- End Message ---

Reply via email to