Re: [PHP] On register_shutdown_function: What might be the problem?
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: > - > > set_time_limit(1); > > function f(){ > set_time_limit(20); > $count=5000; > 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 >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] speed - PHP/MYSQL
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] speed - PHP/MYSQL
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Rasmus' 30 second AJAX Tutorial - [was Re: [PHP] AJAX & PHP]
> 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PEAR DB issue
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: System specific information gathering
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 > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Rasmus' 30 second AJAX Tutorial - [was Re: [PHP] AJAX & PHP]
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] AJAX & PHP
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 BrianGnuPG -> 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] AJAX & PHP
Hmm.. Works for me. Firefox 1.0.6 on gentoo. On 7/23/05, Brian V Bonini <[EMAIL PROTECTED]> wrote: > 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 > > > BrianGnuPG -> 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Don't ejecute a sentence if a field is empty
Hello I'm new: I need to know how can I stop a php sentence if my db is empty, for example I have writed a php sentence, if every fields from mmy db are full, there is no problem, but I delete every values from the all fields in my db when I ejecute my script mysql give me an error, Ej: $fecha = mysql_query("SELECT event_day, event_month, event_year FROM $db_table WHERE event_title = $dia_maximo"); $fecha_max = mysql_fetch_array($fecha); $fecha_maxima = $fecha_max['event_day']; $diames_maximo = $fecha_max['event_month']; wehen I ejecute the script the error message is it: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/cfg/prueba/calendar_este2/index.php on line 277 sorry for my english, I'm cuban -- Este mensaje ha sido analizado por MailScanner en busca de virus y otros contenidos peligrosos, y se considera que está limpio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP and Perl
I am needing to write a front end for an online application written in Perl. Is there a way for PHP to call a module or function written in Perl? Thanks, Linda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] zlib-1.2.3 php-4.4.0
compiled without any problems but when i fired up phpinfo(); it said linked zlib version 1.2.2, so i tried recompiling php but moved the system ones files /usr/lib, /usr/include and placed the old ones in their place but still it says linked zlib version is 1.2.2 within a call to phpinfo();, i also checked the makefile and that had my correct locations for the zlib-1.2.3 version libs. anyone know why? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP and Perl
Linda H wrote: I am needing to write a front end for an online application written in Perl. Is there a way for PHP to call a module or function written in Perl? Firstly, please don't reply to existing threads with a completely new topic. For those of us that use threaded newsreaders, your message is hidden within another thread and is very likely to be missed. In this situation I would simply use the PHP execution functions (exec(), system(), shell_exec(), etc.) to call Perl scripts that use the modules or functions written in Perl. Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Don't ejecute a sentence if a field is empty
Jesús Alain Rodríguez Santos wrote: Hello I'm new: I need to know how can I stop a php sentence if my db is empty, for example I have writed a php sentence, if every fields from mmy db are full, there is no problem, but I delete every values from the all fields in my db when I ejecute my script mysql give me an error, Ej: $fecha = mysql_query("SELECT event_day, event_month, event_year FROM $db_table WHERE event_title = $dia_maximo"); $fecha_max = mysql_fetch_array($fecha); $fecha_maxima = $fecha_max['event_day']; $diames_maximo = $fecha_max['event_month']; wehen I ejecute the script the error message is it: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/cfg/prueba/calendar_este2/index.php on line 277 $fecha = mysql_query("SELECT event_day, event_month, event_year FROM $db_table WHERE event_title = $dia_maximo"); if($fecha) { $fecha_max = mysql_fetch_array($fecha); $fecha_maxima = $fecha_max['event_day']; $diames_maximo = $fecha_max['event_month']; } else { // No row returned... } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] AJAX & PHP
On 7/23/05, Brian V Bonini <[EMAIL PROTECTED]> wrote: > 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. Works fine here, Firefox 1.04 on Debian GNU/Linux 3.1. -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] AJAX & PHP
Yep, I integrated it into one of our in house apps a few weeks back just to try it out and it worked ok. Nothing special, just allowed a user to put in a name in a search box and the js called a php script which did a lookup into the db and returned the results as the user typed but worked well with php. On 7/21/05, balwant singh <[EMAIL PROTECTED]> wrote: > Have anybody tried PHP & AJAX, may please share your experience. also > pls. suggest good link of tutorial on this. > > With Best Wishes > > Balwant Singh > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] speed - PHP/MYSQL
I agree with Jasper here, you want to make it a point to optimize your queries so that fewer trips are made to the database server. On the topic of indexing, I'm curious as to how you did that and if your using it as intended. In your query you are testing columns `time`,`date` so you'll want to make sure that those are two columns that have been indexed. You might want to investigate different types of indexes and how to optimize them too. In my own experience I know that FULLTEXT indexes work wonders for large 'search engine' tables. Multiple Column index - http://dev.mysql.com/doc/mysql/en/multiple-column-indexes.html FULLTEXT index - http://dev.mysql.com/doc/mysql/en/fulltext-search.html Another thing to look at is optimizing your column types. If for instance you have single characters stored in a column that is defined as type BLOB instead of CHAR, your going to slow your queries a bit. - http://dev.mysql.com/doc/mysql/en/data-size.html Good luck! -Joe On Jul 23, 2005, at 6:18 AM, Jasper Bryant-Greene wrote: 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: System specific information gathering
As always, look for someone else's existing project and see how they did it. ;-) http://phpsysinfo.sourceforge.net/ Good Luck! -Joe On Jul 23, 2005, at 9:25 AM, André Medeiros wrote: 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PEAR DB issue
* "Chris Boget" <[EMAIL PROTECTED]>: > 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? You should probably post this to php-pear-general, or to the pear-dev list. If no response there, or if no solutions are forthcoming, file a bug report with PEAR::DB. PEAR::DB *is* under active maintainership, from what I can tell, and some of the more recent changes had to do with MS-SQL report, if memory serves. Good luck! -- Matthew Weier O'Phinney Zend Certified Engineer http://weierophinney.net/matthew/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Don't ejecute a sentence if a field is empty
Jasper Bryant-Greene wrote: Jesús Alain Rodríguez Santos wrote: Hello I'm new: I need to know how can I stop a php sentence if my db is empty, for example I have writed a php sentence, if every fields from mmy db are full, there is no problem, but I delete every values from the all fields in my db when I ejecute my script mysql give me an error, Ej: $fecha = mysql_query("SELECT event_day, event_month, event_year FROM $db_table WHERE event_title = $dia_maximo"); $fecha_max = mysql_fetch_array($fecha); $fecha_maxima = $fecha_max['event_day']; $diames_maximo = $fecha_max['event_month']; wehen I ejecute the script the error message is it: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/cfg/prueba/calendar_este2/index.php on line 277 $fecha = mysql_query("SELECT event_day, event_month, event_year FROM $db_table WHERE event_title = $dia_maximo"); if($fecha) { $fecha_max = mysql_fetch_array($fecha); $fecha_maxima = $fecha_max['event_day']; $diames_maximo = $fecha_max['event_month']; } else { // No row returned... } This is very wrong. If $fecha is false, then it means that the query didn't execute properly, not that there were no rows returned. You should do this instead: $query = "SELECT event_day, event_month, event_year FROM $db_table "; $query .= "WHERE event_title = '".$dia_maximo; $fecha = mysql_query($query); if (!is_resource($fecha)) { die($query."".mysql_error()); } // -- continue with the rest Also, make sure you have a valid connection to the database, mysql_error() will help you with sorting out what is the problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php