OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 25 Jun 2004 05:43:38 -0000 Issue 2841

php-general-digest-helplists.php.net
Date: Fri Jun 25 2004 - 00:43:38 CDT


php-general Digest 25 Jun 2004 05:43:38 -0000 Issue 2841

Topics (messages 188980 through 189033):

Re: a 4 days diary
        188980 by: Chris W. Parker
        188983 by: Chris W. Parker
        188985 by: Pierre
        188989 by: Chris W. Parker
        188994 by: Pierre

malloc() failure - single function document
        188981 by: Joe Lewis
        188993 by: Curt Zirzow
        188999 by: Joe Lewis

Re: Search and replace a String in a file.
        188982 by: Eric L. Sammons
        188984 by: Eric L. Sammons
        188986 by: Justin Patrin

Re: substr_count
        188987 by: Gabe

Finding duplicates in arrays
        188988 by: Chris Lott
        188990 by: Jay Blanchard
        188991 by: Jay Blanchard
        188992 by: Geethanandh Kandasamy

MYSQL Query results in pages
        188995 by: Gus
        188996 by: Matt Matijevich

Re: Multipart Email Problem
        188997 by: Paul Bissex
        189019 by: Manuel Lemos

Re: Parsing entities in XML attributes
        188998 by: Decapode Azur

Streaming
        189000 by: Stephen Craton
        189001 by: svk
        189002 by: Stephen Craton
        189004 by: Justin Patrin
        189009 by: Stephen Craton
        189011 by: Justin Patrin
        189013 by: Stephen Craton
        189014 by: Justin Patrin
        189026 by: Stephen Craton
        189027 by: His Dudeness
        189028 by: Stephen Craton
        189029 by: His Dudeness
        189033 by: Curt Zirzow

a stupid question
        189003 by: Blake Schroeder
        189005 by: Ashwin Purohit
        189006 by: Matt Matijevich
        189007 by: Blake Schroeder
        189008 by: David Goodlad
        189010 by: Matt Matijevich
        189012 by: Vail, Warren
        189016 by: Michal Migurski
        189021 by: Curt Zirzow

About the post Streaming
        189015 by: Pierre
        189017 by: Stephen Craton

Re: MHTML in email
        189018 by: Manuel Lemos
        189022 by: Juan Pablo Herrera

Re: Determine whether $_GET has a value
        189020 by: Al

Re: Sort a text string by last word before separator
        189023 by: Lars Torben Wilson
        189024 by: Lars Torben Wilson
        189025 by: Andre Dubuc

problems with system() call
        189030 by: Jim Rainville
        189031 by: His Dudeness
        189032 by: Jim Rainville

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Pierre <mailto:pierreweb-lance.com>
    on Thursday, June 24, 2004 10:38 AM said:

> I have to code a 4 days diary for a client, schedule every 30 mn and
> with a system of rdv accepted by mail.

what is a 4 days diary? why does it need to be scheduled every 30 mins?
what is "rdv"?

> I really don't know how to
> start to draw a cool diary and to code it correctly to be the most
> reusable as possible. POO or not?

i think you mean OOP? Object Oriented Programming? my answer would be
"yes".

> If you have there any examples of
> this style of coding this is could great or just maybe an idea of how
> I can start my code to have a good one? Just a good direction and way
> of coding to not have many surprises... I hope I was clear

sorry but i don't fully understand what you mean.

chris.

attached mail follows:


Pierre <mailto:pierreweb-lance.com>
    on Thursday, June 24, 2004 10:54 AM said:

> Right it's OOP sorry for the mistake,
> I have to do a diary for only 4 days (the web site is for an
> exhibition, that's why) by rdv I mean a "rendez-vous" an appointment
> if you prefer. So if I resume I need to make a calendar with only for
> days to show the visitor which appointment he has during this four
> days. He can ask an appointment to a present company by mail which
> could answer 'yes' or 'no' by mail
> I hope I was more précised

although i still don't totally understand what you need, i would say it doesn't sound like you need to deal with a database at all. can you not handle all this by hand? will there be a lot of appointments during these four days?

> Sorry for the mistake I'm not English native.

i figured as much. :)

chris.

p.s. i forwarded this to the list so that the rest of the list members can participate and share their ideas.

attached mail follows:


Pierre ROUWENS
pierreweb-lance.com
www.web-lance.com
 
WEB-LANCE
Création intra-internet, CD-ROM etc…
Hébergement WEB et DATA
Solution anti-SPAM et anti-VIRUS pour mails

-----Message d'origine-----
De : Pierre [mailto:pierreweb-lance.com]
Envoyé : jeudi 24 juin 2004 19:15
À : 'Chris W. Parker'
Objet : RE: [PHP] a 4 days diary

So... all datas will be in a mysql base. Many users are gonna use this
system (check the list of exhibitors, ask appointment by mail) and if the
exhibitor accept the appointment I have to insert it my table.
My problem is I don't know how to proceed to have a good code for this
'cause I have to post on the web site the 4 days calendar to the visitor
after he has logged in. So I think I have to use OOP but to draw the
calendar (is with a table a good idea).
Sorry I have trouble to explain it in english
If you have to handle this how do you start your code
Is there any trap I have to escape etc...

Pierre

-----Message d'origine-----
De : Chris W. Parker [mailto:cparkerswatgear.com]
Envoyé : jeudi 24 juin 2004 19:07
À : php-generallists.php.net
Objet : FW: [PHP] a 4 days diary

Pierre <mailto:pierreweb-lance.com>
    on Thursday, June 24, 2004 10:54 AM said:

> Right it's OOP sorry for the mistake,
> I have to do a diary for only 4 days (the web site is for an
> exhibition, that's why) by rdv I mean a "rendez-vous" an appointment
> if you prefer. So if I resume I need to make a calendar with only for
> days to show the visitor which appointment he has during this four
> days. He can ask an appointment to a present company by mail which
> could answer 'yes' or 'no' by mail
> I hope I was more précised

although i still don't totally understand what you need, i would say it
doesn't sound like you need to deal with a database at all. can you not
handle all this by hand? will there be a lot of appointments during these
four days?

> Sorry for the mistake I'm not English native.

i figured as much. :)

chris.

p.s. i forwarded this to the list so that the rest of the list members can
participate and share their ideas.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


Pierre <mailto:pierreweb-lance.com>
    on Thursday, June 24, 2004 11:24 AM said:

> So... all datas will be in a mysql base. Many users are gonna use this
> system (check the list of exhibitors, ask appointment by mail) and if
> the exhibitor accept the appointment I have to insert it my table.
> My problem is I don't know how to proceed to have a good code for this
> 'cause I have to post on the web site the 4 days calendar to the
> visitor after he has logged in. So I think I have to use OOP but to
> draw the calendar (is with a table a good idea).
> Sorry I have trouble to explain it in english
> If you have to handle this how do you start your code
> Is there any trap I have to escape etc...

well there's a lot of things you're going to need to do, and whether or
not you use OOP is up to you.

for your database you'll need the following:

1. a table for the events
2. a table for the participants
3. a table for the appointments. this table will link the participants
to the events.

for your code you'll need to make sure you have some sort of login
system and a way to make appointments by email. the appointment requests
can be a simple form that is sent via the mail() function
(http://php.net/mail).

i can't write your application for your so i hope this helps give you a
starting point.

chris.

p.s. when replying to list mails press the Reply To All button and not
Reply. this will ensure that your mails get sent to the list.

attached mail follows:


OK thx for all
But in fact I'm not really a beginner in php but this is the first time i
have to code this sort of thing so i search the best way to code it.
Mysql tables are ready so this is only how I can handle all by the simplest
way that's all

thx

Pierre

-----Message d'origine-----
De : Chris W. Parker [mailto:cparkerswatgear.com]
Envoyé : jeudi 24 juin 2004 19:33
À : Pierre; php-general
Objet : RE: [PHP] a 4 days diary

Pierre <mailto:pierreweb-lance.com>
    on Thursday, June 24, 2004 11:24 AM said:

> So... all datas will be in a mysql base. Many users are gonna use this
> system (check the list of exhibitors, ask appointment by mail) and if
> the exhibitor accept the appointment I have to insert it my table.
> My problem is I don't know how to proceed to have a good code for this
> 'cause I have to post on the web site the 4 days calendar to the
> visitor after he has logged in. So I think I have to use OOP but to
> draw the calendar (is with a table a good idea).
> Sorry I have trouble to explain it in english
> If you have to handle this how do you start your code
> Is there any trap I have to escape etc...

well there's a lot of things you're going to need to do, and whether or
not you use OOP is up to you.

for your database you'll need the following:

1. a table for the events
2. a table for the participants
3. a table for the appointments. this table will link the participants
to the events.

for your code you'll need to make sure you have some sort of login
system and a way to make appointments by email. the appointment requests
can be a simple form that is sent via the mail() function
(http://php.net/mail).

i can't write your application for your so i hope this helps give you a
starting point.

chris.

p.s. when replying to list mails press the Reply To All button and not
Reply. this will ensure that your mails get sent to the list.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


Hello, all.

I've got a problem, and this is the best place I know of to find the
solution.

I have three PHP programs I'm trying to run. One functions just fine
(located in the home directory, this is a simple mileage tracker for a
couple of my automobiles). One is a feedback form (SMTP), and the other
is a test file only has :

   <?php phpInfo(); ?>

Here's the results :

   mileage.php - works perfectly
   phpinfo.php - results in :
httpd in malloc(): error: allocation failed
[Thu Jun 24 10:18:29 2004] [notice] child pid 19655 exit signal Abort (6)
   feedback.php - results in :
[Thu Jun 24 10:19:23 2004] [notice] child pid 19652 exit signal Bus
error (10)

Those log messages are not what I call good. On the phpinfo.php script,
the memory usage on the server goes through the roof before the messages
get printed to the log file. I'm using FreeBSD5.2-RELEASE, and PHP
4.3.6 running under Apache 2.0.49. I've compiled both apache and
mod_php from ports (similar to "rpm -i"), and also directly from the
source code, to no avail. Does anyone have any ideas as to what is
actually occuring?

Joe

attached mail follows:


* Thus wrote Joe Lewis:
> Hello, all.
>
> I've got a problem, and this is the best place I know of to find the
> solution.
>
> Those log messages are not what I call good. On the phpinfo.php script,
> the memory usage on the server goes through the roof before the messages
> get printed to the log file. I'm using FreeBSD5.2-RELEASE, and PHP
> 4.3.6 running under Apache 2.0.49. I've compiled both apache and
> mod_php from ports (similar to "rpm -i"), and also directly from the
> source code, to no avail. Does anyone have any ideas as to what is
> actually occuring?

first:
  does this happen if you run the script from the command line?

second:
  How is php configured? You can get the configure line if you
  isue:
    php -i

And Finally try this:

apachectl stop

Run:
> gdb /usr/local/apache/bin/httpd

When your at the prompt:
(gdb) run -X -d /usr/local/apache

Then access your phpinfo page via you're browser.

Back at the (gdb) prompt, if apache crashed you will be able to
issue:
{gdb) bt

Whats the contents of that?

Curt
--
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about. No, sir. Our model is the trapezoid!

attached mail follows:


The script works perfectly from the command line. It turns out to be
related directly to Apache 2.0 and the handling of buckets.

gdb gave me a great deal of information. It told me that I have another
module trying to read from an apr_bucket of type POOL which is supplied
by the PHP module. In my module, I put in a line of code to log the
bucket type and also print the contents if it is a POOL type bucket. It
appears that every bucket contains the same thing. It also logs a
bucket type (bucket->type->name) that I have never seen :

bucket type \x18\x10\n\b\x18\x80\x16\b\x18\xe0\x0e\b\x1c\x10\n\bxB\x16\b

So, is there a special way that PHP is supposed to tell other modules
that the brigade is complete (the EOS bucket obviously is not working).
  Additionally, the gdb output revealed that the service is calling
lockname() in the PHP module a great deal. I don't know if this is a
normal occurance or not (output snipped below) :

#12 0x284d6363 in lockname () from /usr/local/libexec/apache2/libphp4.so
#13 0x284a6b46 in lockname () from /usr/local/libexec/apache2/libphp4.so
   ... snip a lot of lines that are the same ...
#27 0x28496e26 in lockname () from /usr/local/libexec/apache2/libphp4.so
#28 0x284d7361 in lockname () from /usr/local/libexec/apache2/libphp4.so

Is it normal to call lockname() that much in PHP? The configuration
line is :

'./configure' '--enable-versioning' '--enable-memory-limit'
'--with-layout=GNU' '--with-zlib-dir=/usr' '--disable-all'
'--with-regex=php' '--disable-cli' '--enable-ctype'
'--with-mysql=/usr/local' '--enable-overload' '--with-pcre-regex=yes'
'--enable-posix' '--enable-session' '--enable-tokenizer'
'--with-expat-dir=/usr/local' '--enable-xml' '--with-zlib=yes'
'--with-apxs2=/usr/local/sbin/apxs' '--prefix=/usr/local'
'i386-portbld-freebsd5.2'

I've put the query out on the apache-modules development mailing list,
but think this is still the more appropriate place to check, because it
is directly related to the PHP module. Any suggestions?

Joe Lewis

Curt Zirzow wrote:

> * Thus wrote Joe Lewis:
>
>>Hello, all.
>>
>>I've got a problem, and this is the best place I know of to find the
>>solution.
>>
>>Those log messages are not what I call good. On the phpinfo.php script,
>>the memory usage on the server goes through the roof before the messages
>>get printed to the log file. I'm using FreeBSD5.2-RELEASE, and PHP
>>4.3.6 running under Apache 2.0.49. I've compiled both apache and
>>mod_php from ports (similar to "rpm -i"), and also directly from the
>>source code, to no avail. Does anyone have any ideas as to what is
>>actually occuring?
>
>
> first:
> does this happen if you run the script from the command line?
>
> second:
> How is php configured? You can get the configure line if you
> isue:
> php -i
>
>
> And Finally try this:
>
> apachectl stop
>
> Run:
>
>>gdb /usr/local/apache/bin/httpd
>
>
> When your at the prompt:
> (gdb) run -X -d /usr/local/apache
>
> Then access your phpinfo page via you're browser.
>
> Back at the (gdb) prompt, if apache crashed you will be able to
> issue:
> {gdb) bt
>
> Whats the contents of that?
>
> Curt

attached mail follows:


First let me thank you for pointing me to PEAR. Now for the problem. Here is
my code:

<?php
         require_once 'File/SearchReplace.php';

         $serverName = "pxt010";
        $dir = "/home/ossadmin/";
         $file = "server-info.temp";

        $nfile = "server-$serverName.spec";

        $ignoreline = array("%", "#");

         system("sudo /bin/cp $dir$file $dir$nfile", $return);
        if (file_exists($dir.$nfile)) {
                print "<h3>File exists.</h3>";
                $snr = File_SearchReplace("server-temp", "server-$serverName", $nfile,
                                  $dir, false, $ignoreline);
                  $snr -> doSearch();
         } else {
                print "<h3>File does not Exist</h3>";
         }
        
?>

Here is my output:

File exists.

Fatal error: Call to undefined function: file_searchreplace() in
/home/els/SrvrBuild/rpl.php on line 15

I have tried both include ... and require_once ... with the same result.

Help?

Thank you!
>===== Original Message From Justin Patrin <papercranegmail.com> =====
>There's a PEAR package for just this. :-)
>http://pear.php.net/package/File_SearchReplace
>
>On Thu, 24 Jun 2004 12:58:08 -0400, Eric L. Sammons <esammonsvt.edu> wrote:
>>
>> Being new to PHP this task seems to be little out of my reach right now. I
>> wonder if anyone could tell me how, as I read a file, line by line, search
for
>> and then replace a given string?
>>
>> The lines in the file will appear as such:
>>
>> Summary: Some Summary
>> Name: Some-Name
>> Version: x.x
>> .
>> .
>> .
>>
>> Basically I will open the file, read its lines one by one and I want to
>> replace Some-Name with Some-other-Name.
>>
>> Thank you!
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
>
>--
>paperCrane --Justin Patrin--
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


One last thing, I know someone will ask...

Yes I have installed the PEAR package:
pear info File_SearchReplace
About File_SearchReplace-1.0.1
==============================
Provides
Package File_SearchReplace
Summary Performs search and replace routines
Description Provides various functions to perform
                search/replace
                on files. Preg/Ereg regex supported along with
                faster
                but more basic str_replace routine.
Maintainers Richard Heyes <richardphp.net> (lead)
Version 1.0.1
Release Date 2002-07-27
Release License BSD
Release State stable
Release Notes License change
Last Modified 2004-06-24

pear list
Installed packages:
===================
Package Version State
Archive_Tar 0.9 stable
Archive_Tar 1.1 stable
Console_Getopt 1.0 stable
Console_Getopt 1.2 stable
DB 1.6.2 stable
DB 1.3 stable
File_SearchReplace 1.0.1 stable
HTTP 1.2 stable
HTTP 1.2.2 stable
Mail 1.1.3 stable
Mail 1.0.1 stable
Net_SMTP 1.2.3 stable
Net_SMTP 1.0 stable
Net_Socket 1.0.1 stable
Net_Socket 1.0.1 stable
PEAR 1.3.2 stable
PEAR 1.1 stable
XML_Parser 1.0.1 stable
XML_Parser 1.0.1 stable
XML_RPC 1.0.4 stable
XML_RPC 1.1.0 stable

>===== Original Message From "Eric L. Sammons" <esammonsvt.edu> =====
First let me thank you for pointing me to PEAR. Now for the problem. Here is
my code:

<?php
         require_once 'File/SearchReplace.php';

         $serverName = "pxt010";
        $dir = "/home/ossadmin/";
         $file = "server-info.temp";

        $nfile = "server-$serverName.spec";

        $ignoreline = array("%", "#");

         system("sudo /bin/cp $dir$file $dir$nfile", $return);
        if (file_exists($dir.$nfile)) {
                print "<h3>File exists.</h3>";
                $snr = File_SearchReplace("server-temp", "server-$serverName", $nfile,
                                  $dir, false, $ignoreline);
                  $snr -> doSearch();
         } else {
                print "<h3>File does not Exist</h3>";
         }

?>

Here is my output:

File exists.

Fatal error: Call to undefined function: file_searchreplace() in
/home/els/SrvrBuild/rpl.php on line 15

I have tried both include ... and require_once ... with the same result.

Help?

Thank you!
>===== Original Message From Justin Patrin <papercranegmail.com> =====
>There's a PEAR package for just this. :-)
>http://pear.php.net/package/File_SearchReplace
>
>On Thu, 24 Jun 2004 12:58:08 -0400, Eric L. Sammons <esammonsvt.edu> wrote:
>>
>> Being new to PHP this task seems to be little out of my reach right now. I
>> wonder if anyone could tell me how, as I read a file, line by line, search
for
>> and then replace a given string?
>>
>> The lines in the file will appear as such:
>>
>> Summary: Some Summary
>> Name: Some-Name
>> Version: x.x
>> .
>> .
>> .
>>
>> Basically I will open the file, read its lines one by one and I want to
>> replace Some-Name with Some-other-Name.
>>
>> Thank you!
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
>
>--
>paperCrane --Justin Patrin--
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


You need to do:
$snr = new File_SearchReplace(...);

On Thu, 24 Jun 2004 13:52:55 -0400, Eric L. Sammons <esammonsvt.edu> wrote:
>
> First let me thank you for pointing me to PEAR. Now for the problem. Here is
> my code:
>
> <?php
> require_once 'File/SearchReplace.php';
>
> $serverName = "pxt010";
> $dir = "/home/ossadmin/";
> $file = "server-info.temp";
>
> $nfile = "server-$serverName.spec";
>
> $ignoreline = array("%", "#");
>
> system("sudo /bin/cp $dir$file $dir$nfile", $return);
> if (file_exists($dir.$nfile)) {
> print "<h3>File exists.</h3>";
> $snr = File_SearchReplace("server-temp", "server-$serverName", $nfile,
> $dir, false, $ignoreline);
> $snr -> doSearch();
> } else {
> print "<h3>File does not Exist</h3>";
> }
>
> ?>
>
> Here is my output:
>
> File exists.
>
> Fatal error: Call to undefined function: file_searchreplace() in
> /home/els/SrvrBuild/rpl.php on line 15
>
> I have tried both include ... and require_once ... with the same result.
>
> Help?
>
> Thank you!
> >===== Original Message From Justin Patrin <papercranegmail.com> =====
>
>
> >There's a PEAR package for just this. :-)
> >http://pear.php.net/package/File_SearchReplace
> >
> >On Thu, 24 Jun 2004 12:58:08 -0400, Eric L. Sammons <esammonsvt.edu> wrote:
> >>
> >> Being new to PHP this task seems to be little out of my reach right now. I
> >> wonder if anyone could tell me how, as I read a file, line by line, search
> for
> >> and then replace a given string?
> >>
> >> The lines in the file will appear as such:
> >>
> >> Summary: Some Summary
> >> Name: Some-Name
> >> Version: x.x
> >> .
> >> .
> >> .
> >>
> >> Basically I will open the file, read its lines one by one and I want to
> >> replace Some-Name with Some-other-Name.
> >>
> >> Thank you!
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
> >
> >
> >
> >--
> >paperCrane --Justin Patrin--
> >
> >--
> >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
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


Matt Matijevich wrote:

> [snip]
> Anyway, to get this to return a count of two?
> [/snip]
>
> just strtolower or strtoupper both $strHaystack and $strNeedle

I think I've been looking at the same code for so long, I'm missing the
blatantly obvious stuff now... I can't believe I didn't think of that.
  Thanks Matt.

attached mail follows:


Given two arrays, I want to find the "records" which are duplicates.
What is the simplest approach? And should I use a different approach
to compare three or more arrays to find only duplicates that occur in
all of them?

c
--
Chris Lott

attached mail follows:


[snip]
Given two arrays, I want to find the "records" which are duplicates.
What is the simplest approach? And should I use a different approach
to compare three or more arrays to find only duplicates that occur in
all of them?
[/snip]

http://us2.php.net/manual/en/function.array-diff.php

The manual can be your friend.

attached mail follows:


[snip]
[snip]
Given two arrays, I want to find the "records" which are duplicates.
What is the simplest approach? And should I use a different approach
to compare three or more arrays to find only duplicates that occur in
all of them?
[/snip]

http://us2.php.net/manual/en/function.array-diff.php

The manual can be your friend.
[/snip]

Sorry, http://us2.php.net/manual/en/function.array-intersect.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


use array_unique

http://us4.php.net/manual/en/function.array-unique.php

On Thu, 24 Jun 2004 10:33:04 -0800, Chris Lott <chris.lottgmail.com> wrote:
>
> Given two arrays, I want to find the "records" which are duplicates.
> What is the simplest approach? And should I use a different approach
> to compare three or more arrays to find only duplicates that occur in
> all of them?
>
> c
> --
> Chris Lott
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


Hi. I want to query some data in MYSQL and show the results in page order in
some fashion (ORDER BY ...)
I've been using the LIMIT sentence like this

       LIMIT offset, max_per_page

so if max_per_page = 5 then the first time the sentence will be "LIMIT 0,
5", in page 2 "LIMIT 5,5" and so no.

My problem is how to calculate how many rows the result returned. By now,
the first time I'm querying without the LIMIT sentenced, and then store
mysql_num_rows() to know have many pages there will be (i.e. maxrows =
mysql_num_rows()/5).

Is this right? Is there other efficent way to do it?
What about if data changes (i.e. new records are added) while the user
browses through pages?

Thanks!

attached mail follows:


[snip]
Is this right? Is there other efficent way to do it?
What about if data changes (i.e. new records are added) while the user
browses through pages?
[/snip]

on each page do a:

SELECT count(*) FROM table WHERE your_condition

this will give you your total number of results

attached mail follows:


I had the same problem a few months ago. I switched to Mail::mime
thinking that the problem was my homebrew code, but still the same
thing -- Outlook didn't recognize the message as multipart.

The fix was changing the newline sequence from "\r\n" to "\n".

The Mail::mime constructor allows you to change this value, so in my
code the change boiled down to:

      $mime = new Mail_mime ("\n");

Hope this works for you.

pb

On Thu, 24 Jun 2004 12:27:17 +0100, Matt MacLeod <mattbigbarn.co.uk> wrote:
>
> I have a script that sends a multipart email from a php page.
>
> The script appears to work fine on my mail client (Mail on Mac OSX) and
> on an online email reader (mail2web.com).
>
> However a colleague using Outlook on Windows 2003 views the whole email
> (ie the raw code - both the text only and the HTML) and when I sent an
> email to his hotmail account, hotmail simply displayed a blank page.

[snip]
--

attached mail follows:


Hello,

On 06/24/2004 08:27 AM, Matt Macleod wrote:
> I have a script that sends a multipart email from a php page.
>
> The script appears to work fine on my mail client (Mail on Mac OSX) and
> on an online email reader (mail2web.com).
>
> However a colleague using Outlook on Windows 2003 views the whole email
> (ie the raw code - both the text only and the HTML) and when I sent an
> email to his hotmail account, hotmail simply displayed a blank page.

This looks like a bug in the mail() function.

You may want to try this class for composing and sending messages that
comes with an example for sending HTML messages with alternative text
parts. The class has some workarounds to some of the mail() function
problems.

http://www.phpclasses.org/mimemessage

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html

attached mail follows:


Hi,

The problem I had has not exactly the same, but quite close,
it was to make a pure xml template system both data and template,
anyway it was due to the same expat design problem, which is
the entities that are located in attribute values inside tags.

The solution I have used was just to preserve expat from parsing entities,
and only need 2 additionnal lines in the script (3 with the constant define;).

Just after the input replace the char '&' with something else,
and just before the output put it back :

/** Preserve entities from removal */
define('ENTITY_PRESERVE', '£$¥¤');

[...]

#replacement at input :

        while ($data = fread($fp, 4096)) {
            $data = str_replace('&', ENTITY_PRESERVE, $data); // HERE
            if (!xml_parse($this->_parser, $data, feof($fp))) {
                die(sprintf("XML error: %s at ligne %d",
                            xml_error_string(xml_get_error_code($xml_parser)),
                            xml_get_current_line_number($xml_parser)));
            }
        }

[...]

#replacement for output with your code :

function start_tag($parser, $name, $attrs)
{
    global $text;
    if($name == "CUSTOMTEXT") {
        $text = $attrs['TEXT'];
        $text = str_replace(ENTITY_PRESERVE, '&', $text); // Put '&' back !
    }
    // more tags here ..
}

I am sure that there could be better solutions.
If someone know about one, please email me :)

Cheers
--
Gabriel Birke a écrit :
> Hello!
>
> I've got an XML file that has the following tag:
> <customtext text="first line&lt;br /&gt;second line" />
>
> I parse it with the following handler (simplified a bit):
>
> function start_tag($parser, $name, $attrs)
> {
> global $text;
> if($name == "CUSTOMTEXT")
> $text = $attrs['TEXT'];
> // more tags here ..
> }
>
> When I echo $text in a HTML page, I see a linebreak - just as I
> intended.
>
> One of our customers has the script installed on his server and he
> doesn't see a linebreak but sees <br /> printed out. He has to write
> the tag like this:
> <customtext text="first line <br />second line" />
>
> Now I've got two questions:
> 1. Which tag is correct XML?
> 2. What is the cause of this?
>
> I'm running the script with PHP 4.1.2 and EXPAT Version 1.95.2
> Don't know what our customer has running.
>
> With best regards
>
> Gabriel Birke

attached mail follows:


I was browsing the net and I found a PHP chat script that claimed that it
does not refresh, rather it has "streaming text". This got my interest and
was wondering how the script did it. I downloaded it's source code but
couldn't find anything useful in it, very hard to read in my opinion. I did
a search on PHP.net for streaming but I couldn't understand much of that,
just my noobishness I suppose.
 
How exactly would you go about streaming in PHP anyway? This has my interest
now...
 
Thanks,
Stephen Craton
http://www.melchior.us <http://www.melchior.us/>
 

attached mail follows:


On Thu, 2004-06-24 at 16:41, Stephenpp

To use "streaming", you have to :
Turn off output buffering: ob_end_clean()
and flush the output has it comes : flush()

It is useful to note that :
"Some versions of Microsoft Internet Explorer will only start to display
the page after they have received 256 bytes of output, so you may need
to send extra whitespace before flushing to get those browsers to
display the page. "

and
"Pad your output with necessary spaces, wrap your progressing data
around open (<table>) and end (</table>) tags, and then call flush() so
that one script will work for Netscape as well.
"

> I was browsing the net and I found a PHP chat script that claimed that it
> does not refresh, rather it has "streaming text". This got my interest and
> was wondering how the script did it. I downloaded it's source code but
> couldn't find anything useful in it, very hard to read in my opinion. I did
> a search on PHP.net for streaming but I couldn't understand much of that,
> just my noobishness I suppose.
>
> How exactly would you go about streaming in PHP anyway? This has my interest
> now...
>
> Thanks,
> Stephen Craton
> http://www.melchior.us <http://www.melchior.us/>
>

attached mail follows:


Thanks for this, but how do I use it? Do I just put the ob_end_clean() at
the opening the page I want to stream and then put flush() at the end?
 
Thanks,
Stephen Craton
http://www.melchior.us

-----Original Message-----
From: svk [mailto:svkksearch.f2o.org]
Sent: Thursday, June 24, 2004 4:25 PM
To: php-generallists.php.net
Subject: Re: [PHP] Streaming

On Thu, 2004-06-24 at 16:41, Stephenpp

To use "streaming", you have to :
Turn off output buffering: ob_end_clean() and flush the output has it comes
: flush()

It is useful to note that :
"Some versions of Microsoft Internet Explorer will only start to display the
page after they have received 256 bytes of output, so you may need to send
extra whitespace before flushing to get those browsers to display the page.
"

and
"Pad your output with necessary spaces, wrap your progressing data around
open (<table>) and end (</table>) tags, and then call flush() so that one
script will work for Netscape as well.
"

> I was browsing the net and I found a PHP chat script that claimed that
> it does not refresh, rather it has "streaming text". This got my
> interest and was wondering how the script did it. I downloaded it's
> source code but couldn't find anything useful in it, very hard to read
> in my opinion. I did a search on PHP.net for streaming but I couldn't
> understand much of that, just my noobishness I suppose.
>
> How exactly would you go about streaming in PHP anyway? This has my
> interest now...
>
> Thanks,
> Stephen Craton
> http://www.melchior.us <http://www.melchior.us/>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


ob_end_clean() goes at the top.
flush() goes after *every* pice of info you want to show real-time.
Basically, after every echo or group of echos.

On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton
<webmastermelchior.us> wrote:
>
> Thanks for this, but how do I use it? Do I just put the ob_end_clean() at
> the opening the page I want to stream and then put flush() at the end?
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
>
>
> -----Original Message-----
> From: svk [mailto:svkksearch.f2o.org]
> Sent: Thursday, June 24, 2004 4:25 PM
> To: php-generallists.php.net
> Subject: Re: [PHP] Streaming
>
> On Thu, 2004-06-24 at 16:41, Stephenpp
>
> To use "streaming", you have to :
> Turn off output buffering: ob_end_clean() and flush the output has it comes
> : flush()
>
> It is useful to note that :
> "Some versions of Microsoft Internet Explorer will only start to display the
> page after they have received 256 bytes of output, so you may need to send
> extra whitespace before flushing to get those browsers to display the page.
> "
>
> and
> "Pad your output with necessary spaces, wrap your progressing data around
> open (<table>) and end (</table>) tags, and then call flush() so that one
> script will work for Netscape as well.
> "
>
> > I was browsing the net and I found a PHP chat script that claimed that
> > it does not refresh, rather it has "streaming text". This got my
> > interest and was wondering how the script did it. I downloaded it's
> > source code but couldn't find anything useful in it, very hard to read
> > in my opinion. I did a search on PHP.net for streaming but I couldn't
> > understand much of that, just my noobishness I suppose.
> >
> > How exactly would you go about streaming in PHP anyway? This has my
> > interest now...
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us <http://www.melchior.us/>
> >
>
> --
> 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
>
>
> !DSPAM:40db491f54512097234068!
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


I just put it into my script, and it doesn't seem to be working. I put
ob_end_clean(); at the top of the script, but here's the while loop I have:

        while($db->next_record()):
        echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
        $sql = "SELECT emote, image FROM c_emotes";
        $result = mysql_query($sql, $db->linkid);
        while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $emotes[] = $row['emote'];
        $images[] = "<img src='".$row['image']."'>";
        }
        if($db->Record['system'] != 1) {
                $message = htmlentities($db->Record["text"]);
        } else {
                $message = $db->Record["text"];
        }
        $message = str_replace($emotes, $images, $message);
        echo $message."<br>\n";
        flush();
        endwhile;

It displays just fine if you refresh, but unless you refresh, you don't see
any new data. Any ideas?
 
Thanks,
Stephen Craton
http://www.melchior.us

-----Original Message-----
From: Justin Patrin [mailto:papercranegmail.com]
Sent: Thursday, June 24, 2004 4:47 PM
To: Stephen Craton
Cc: PHP List
Subject: Re: [PHP] Streaming

ob_end_clean() goes at the top.
flush() goes after *every* pice of info you want to show real-time.
Basically, after every echo or group of echos.

On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton <webmastermelchior.us>
wrote:
>
> Thanks for this, but how do I use it? Do I just put the ob_end_clean()
> at the opening the page I want to stream and then put flush() at the end?
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
>
>
> -----Original Message-----
> From: svk [mailto:svkksearch.f2o.org]
> Sent: Thursday, June 24, 2004 4:25 PM
> To: php-generallists.php.net
> Subject: Re: [PHP] Streaming
>
> On Thu, 2004-06-24 at 16:41, Stephenpp
>
> To use "streaming", you have to :
> Turn off output buffering: ob_end_clean() and flush the output has it
> comes
> : flush()
>
> It is useful to note that :
> "Some versions of Microsoft Internet Explorer will only start to
> display the page after they have received 256 bytes of output, so you
> may need to send extra whitespace before flushing to get those browsers to
display the page.
> "
>
> and
> "Pad your output with necessary spaces, wrap your progressing data
> around open (<table>) and end (</table>) tags, and then call flush()
> so that one script will work for Netscape as well.
> "
>
> > I was browsing the net and I found a PHP chat script that claimed
> > that it does not refresh, rather it has "streaming text". This got
> > my interest and was wondering how the script did it. I downloaded
> > it's source code but couldn't find anything useful in it, very hard
> > to read in my opinion. I did a search on PHP.net for streaming but I
> > couldn't understand much of that, just my noobishness I suppose.
> >
> > How exactly would you go about streaming in PHP anyway? This has my
> > interest now...
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us <http://www.melchior.us/>
> >
>
> --
> 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
>
>
> !DSPAM:40db491f54512097234068!
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


Your script is ending, so the page ends. PHP (HTTP) isn't really
supposed to do "streaming." If you want it to "stream" you have to
keep the script running. Add something like this:

while(true) {
       while($db->next_record()) {
       echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
       $sql = "SELECT emote, image FROM c_emotes";
       $result = mysql_query($sql, $db->linkid);
       while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
       $emotes[] = $row['emote'];
       $images[] = "<img src='".$row['image']."'>";
       }
       if($db->Record['system'] != 1) {
               $message = htmlentities($db->Record["text"]);
       } else {
               $message = $db->Record["text"];
       }
       $message = str_replace($emotes, $images, $message);
       echo $message."<br>\n";
       flush();
    }
    sleep(5);
    set_time_limit(30);
}

This will actually run *forever* and will loop through the records
again and again, probably giving yu the same content as before. You
would need some kind of way to know which records are "new" so you can
only display them in the loop. I would suggest adding a "time >
$savedTime" or some such to the loop.

Please note, though, that this is a *very large hack*. You're not
supposed to keep your scripts running forever. If you really want to
"stream", write a Java/C/C++/C#/etc. app. Or, if you're feeling
adventurous, use JavaScript.

On Thu, 24 Jun 2004 16:54:57 -0500, Stephen Craton
<webmastermelchior.us> wrote:
>
> I just put it into my script, and it doesn't seem to be working. I put
> ob_end_clean(); at the top of the script, but here's the while loop I have:
>
> while($db->next_record()):
> echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> $sql = "SELECT emote, image FROM c_emotes";
> $result = mysql_query($sql, $db->linkid);
> while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> $emotes[] = $row['emote'];
> $images[] = "<img src='".$row['image']."'>";
> }
> if($db->Record['system'] != 1) {
> $message = htmlentities($db->Record["text"]);
> } else {
> $message = $db->Record["text"];
> }
> $message = str_replace($emotes, $images, $message);
> echo $message."<br>\n";
> flush();
> endwhile;
>
> It displays just fine if you refresh, but unless you refresh, you don't see
> any new data. Any ideas?
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
>
>
> -----Original Message-----
> From: Justin Patrin [mailto:papercranegmail.com]
> Sent: Thursday, June 24, 2004 4:47 PM
> To: Stephen Craton
> Cc: PHP List
> Subject: Re: [PHP] Streaming
>
> ob_end_clean() goes at the top.
> flush() goes after *every* pice of info you want to show real-time.
> Basically, after every echo or group of echos.
>
> On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton <webmastermelchior.us>
> wrote:
> >
> > Thanks for this, but how do I use it? Do I just put the ob_end_clean()
> > at the opening the page I want to stream and then put flush() at the end?
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us
> >
> >
> >
> > -----Original Message-----
> > From: svk [mailto:svkksearch.f2o.org]
> > Sent: Thursday, June 24, 2004 4:25 PM
> > To: php-generallists.php.net
> > Subject: Re: [PHP] Streaming
> >
> > On Thu, 2004-06-24 at 16:41, Stephenpp
> >
> > To use "streaming", you have to :
> > Turn off output buffering: ob_end_clean() and flush the output has it
> > comes
> > : flush()
> >
> > It is useful to note that :
> > "Some versions of Microsoft Internet Explorer will only start to
> > display the page after they have received 256 bytes of output, so you
> > may need to send extra whitespace before flushing to get those browsers to
> display the page.
> > "
> >
> > and
> > "Pad your output with necessary spaces, wrap your progressing data
> > around open (<table>) and end (</table>) tags, and then call flush()
> > so that one script will work for Netscape as well.
> > "
> >
> > > I was browsing the net and I found a PHP chat script that claimed
> > > that it does not refresh, rather it has "streaming text". This got
> > > my interest and was wondering how the script did it. I downloaded
> > > it's source code but couldn't find anything useful in it, very hard
> > > to read in my opinion. I did a search on PHP.net for streaming but I
> > > couldn't understand much of that, just my noobishness I suppose.
> > >
> > > How exactly would you go about streaming in PHP anyway? This has my
> > > interest now...
> > >
> > > Thanks,
> > > Stephen Craton
> > > http://www.melchior.us <http://www.melchior.us/>
> > >
> >
> > --
> > 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
> >
> >
> >
> >
> >
>
>
> --
> paperCrane --Justin Patrin--
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> !DSPAM:40db4bef62072026120151!
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


Thanks for all the help here.

The only question I have left is bandwidth. Would a while(true) { } loop hog
up enormous ammounts of bandwidth or just sit there quietly bugging noone?
The only other option I have going for me is the iframe hack, which I'm
getting annoyed of...
 
Thanks,
Stephen Craton
http://www.melchior.us

-----Original Message-----
From: Justin Patrin [mailto:papercranegmail.com]
Sent: Thursday, June 24, 2004 5:01 PM
To: Stephen Craton
Cc: PHP List
Subject: Re: [PHP] Streaming

Your script is ending, so the page ends. PHP (HTTP) isn't really supposed to
do "streaming." If you want it to "stream" you have to keep the script
running. Add something like this:

while(true) {
       while($db->next_record()) {
       echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
       $sql = "SELECT emote, image FROM c_emotes";
       $result = mysql_query($sql, $db->linkid);
       while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
       $emotes[] = $row['emote'];
       $images[] = "<img src='".$row['image']."'>";
       }
       if($db->Record['system'] != 1) {
               $message = htmlentities($db->Record["text"]);
       } else {
               $message = $db->Record["text"];
       }
       $message = str_replace($emotes, $images, $message);
       echo $message."<br>\n";
       flush();
    }
    sleep(5);
    set_time_limit(30);
}

This will actually run *forever* and will loop through the records again and
again, probably giving yu the same content as before. You would need some
kind of way to know which records are "new" so you can only display them in
the loop. I would suggest adding a "time > $savedTime" or some such to the
loop.

Please note, though, that this is a *very large hack*. You're not supposed
to keep your scripts running forever. If you really want to "stream", write
a Java/C/C++/C#/etc. app. Or, if you're feeling adventurous, use JavaScript.

On Thu, 24 Jun 2004 16:54:57 -0500, Stephen Craton <webmastermelchior.us>
wrote:
>
> I just put it into my script, and it doesn't seem to be working. I put
> ob_end_clean(); at the top of the script, but here's the while loop I
have:
>
> while($db->next_record()):
> echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> $sql = "SELECT emote, image FROM c_emotes";
> $result = mysql_query($sql, $db->linkid);
> while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> $emotes[] = $row['emote'];
> $images[] = "<img src='".$row['image']."'>";
> }
> if($db->Record['system'] != 1) {
> $message = htmlentities($db->Record["text"]);
> } else {
> $message = $db->Record["text"];
> }
> $message = str_replace($emotes, $images, $message);
> echo $message."<br>\n";
> flush();
> endwhile;
>
> It displays just fine if you refresh, but unless you refresh, you
> don't see any new data. Any ideas?
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
>
>
> -----Original Message-----
> From: Justin Patrin [mailto:papercranegmail.com]
> Sent: Thursday, June 24, 2004 4:47 PM
> To: Stephen Craton
> Cc: PHP List
> Subject: Re: [PHP] Streaming
>
> ob_end_clean() goes at the top.
> flush() goes after *every* pice of info you want to show real-time.
> Basically, after every echo or group of echos.
>
> On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton
> <webmastermelchior.us>
> wrote:
> >
> > Thanks for this, but how do I use it? Do I just put the
> > ob_end_clean() at the opening the page I want to stream and then put
flush() at the end?
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us
> >
> >
> >
> > -----Original Message-----
> > From: svk [mailto:svkksearch.f2o.org]
> > Sent: Thursday, June 24, 2004 4:25 PM
> > To: php-generallists.php.net
> > Subject: Re: [PHP] Streaming
> >
> > On Thu, 2004-06-24 at 16:41, Stephenpp
> >
> > To use "streaming", you have to :
> > Turn off output buffering: ob_end_clean() and flush the output has
> > it comes
> > : flush()
> >
> > It is useful to note that :
> > "Some versions of Microsoft Internet Explorer will only start to
> > display the page after they have received 256 bytes of output, so
> > you may need to send extra whitespace before flushing to get those
> > browsers to
> display the page.
> > "
> >
> > and
> > "Pad your output with necessary spaces, wrap your progressing data
> > around open (<table>) and end (</table>) tags, and then call flush()
> > so that one script will work for Netscape as well.
> > "
> >
> > > I was browsing the net and I found a PHP chat script that claimed
> > > that it does not refresh, rather it has "streaming text". This got
> > > my interest and was wondering how the script did it. I downloaded
> > > it's source code but couldn't find anything useful in it, very
> > > hard to read in my opinion. I did a search on PHP.net for
> > > streaming but I couldn't understand much of that, just my noobishness
I suppose.
> > >
> > > How exactly would you go about streaming in PHP anyway? This has
> > > my interest now...
> > >
> > > Thanks,
> > > Stephen Craton
> > > http://www.melchior.us <http://www.melchior.us/>
> > >
> >
> > --
> > 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
> >
> >
> >
> >
> >
>
>
> --
> paperCrane --Justin Patrin--
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>
>
> !DSPAM:40db4bef62072026120151!
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


It will use up CPU time and bandwidth, yes. It should take less
bandwidth than the "refresh constantly" version, but only if you code
it right.

You could also write a little JS to pull some content from the server
(get messages after a certain time / message id) and inject them into
the page. This is really the best solution if you want to stay in the
browser and not do Flash or Java.

On Thu, 24 Jun 2004 17:24:31 -0500, Stephen Craton
<webmastermelchior.us> wrote:
>
> Thanks for all the help here.
>
> The only question I have left is bandwidth. Would a while(true) { } loop hog
> up enormous ammounts of bandwidth or just sit there quietly bugging noone?
> The only other option I have going for me is the iframe hack, which I'm
> getting annoyed of...
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
> -----Original Message-----
> From: Justin Patrin [mailto:papercranegmail.com]
> Sent: Thursday, June 24, 2004 5:01 PM
> To: Stephen Craton
> Cc: PHP List
> Subject: Re: [PHP] Streaming
>
> Your script is ending, so the page ends. PHP (HTTP) isn't really supposed to
> do "streaming." If you want it to "stream" you have to keep the script
> running. Add something like this:
>
> while(true) {
> while($db->next_record()) {
> echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> $sql = "SELECT emote, image FROM c_emotes";
> $result = mysql_query($sql, $db->linkid);
> while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> $emotes[] = $row['emote'];
> $images[] = "<img src='".$row['image']."'>";
> }
> if($db->Record['system'] != 1) {
> $message = htmlentities($db->Record["text"]);
> } else {
> $message = $db->Record["text"];
> }
> $message = str_replace($emotes, $images, $message);
> echo $message."<br>\n";
> flush();
> }
> sleep(5);
> set_time_limit(30);
> }
>
> This will actually run *forever* and will loop through the records again and
> again, probably giving yu the same content as before. You would need some
> kind of way to know which records are "new" so you can only display them in
> the loop. I would suggest adding a "time > $savedTime" or some such to the
> loop.
>
> Please note, though, that this is a *very large hack*. You're not supposed
> to keep your scripts running forever. If you really want to "stream", write
> a Java/C/C++/C#/etc. app. Or, if you're feeling adventurous, use JavaScript.
>
> On Thu, 24 Jun 2004 16:54:57 -0500, Stephen Craton <webmastermelchior.us>
> wrote:
> >
> > I just put it into my script, and it doesn't seem to be working. I put
> > ob_end_clean(); at the top of the script, but here's the while loop I
> have:
> >
> > while($db->next_record()):
> > echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> > $sql = "SELECT emote, image FROM c_emotes";
> > $result = mysql_query($sql, $db->linkid);
> > while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> > $emotes[] = $row['emote'];
> > $images[] = "<img src='".$row['image']."'>";
> > }
> > if($db->Record['system'] != 1) {
> > $message = htmlentities($db->Record["text"]);
> > } else {
> > $message = $db->Record["text"];
> > }
> > $message = str_replace($emotes, $images, $message);
> > echo $message."<br>\n";
> > flush();
> > endwhile;
> >
> > It displays just fine if you refresh, but unless you refresh, you
> > don't see any new data. Any ideas?
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us
> >
> >
> >
> > -----Original Message-----
> > From: Justin Patrin [mailto:papercranegmail.com]
> > Sent: Thursday, June 24, 2004 4:47 PM
> > To: Stephen Craton
> > Cc: PHP List
> > Subject: Re: [PHP] Streaming
> >
> > ob_end_clean() goes at the top.
> > flush() goes after *every* pice of info you want to show real-time.
> > Basically, after every echo or group of echos.
> >
> > On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton
> > <webmastermelchior.us>
> > wrote:
> > >
> > > Thanks for this, but how do I use it? Do I just put the
> > > ob_end_clean() at the opening the page I want to stream and then put
> flush() at the end?
> > >
> > > Thanks,
> > > Stephen Craton
> > > http://www.melchior.us
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: svk [mailto:svkksearch.f2o.org]
> > > Sent: Thursday, June 24, 2004 4:25 PM
> > > To: php-generallists.php.net
> > > Subject: Re: [PHP] Streaming
> > >
> > > On Thu, 2004-06-24 at 16:41, Stephenpp
> > >
> > > To use "streaming", you have to :
> > > Turn off output buffering: ob_end_clean() and flush the output has
> > > it comes
> > > : flush()
> > >
> > > It is useful to note that :
> > > "Some versions of Microsoft Internet Explorer will only start to
> > > display the page after they have received 256 bytes of output, so
> > > you may need to send extra whitespace before flushing to get those
> > > browsers to
> > display the page.
> > > "
> > >
> > > and
> > > "Pad your output with necessary spaces, wrap your progressing data
> > > around open (<table>) and end (</table>) tags, and then call flush()
> > > so that one script will work for Netscape as well.
> > > "
> > >
> > > > I was browsing the net and I found a PHP chat script that claimed
> > > > that it does not refresh, rather it has "streaming text". This got
> > > > my interest and was wondering how the script did it. I downloaded
> > > > it's source code but couldn't find anything useful in it, very
> > > > hard to read in my opinion. I did a search on PHP.net for
> > > > streaming but I couldn't understand much of that, just my noobishness
> I suppose.
> > > >
> > > > How exactly would you go about streaming in PHP anyway? This has
> > > > my interest now...
> > > >
> > > > Thanks,
> > > > Stephen Craton
> > > > http://www.melchior.us <http://www.melchior.us/>
> > > >
> > >
> > > --
> > > 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
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > paperCrane --Justin Patrin--
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> > http://www.php.net/unsub.php
> >
> >
> >
> >
> >
>
> --
> paperCrane --Justin Patrin--
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> !DSPAM:40db52b778403726210510!
>
>

--
paperCrane --Justin Patrin--

attached mail follows:


I've been wracking my brains for the past few hours trying to figure out
this streaming business and the ways to avoid refreshing and polling the
server for data. I spent a few hours playing Sherlock Holmes in the
phpOpenChat software which is where I first found this technique, but I
didn't succeed.

The most I could find out is that it does indeed use output buffering, but
I'm not quite sure how it's looping the data (most I could find out it was
doing a do {} while() loop with an array called $lines) to display it
without illeffects on the processor. On top of that, I couldn't figure out
how it was printing and checking lines over and over again for a new message
to show in all the other client windows.

So my question is, does anyone know how the phpOpenChat system works? Can
anyone provide some insight into the world of "streaming" and avoiding the
refresh game?

I was also thinking of Javascript like you said, but again, I came back to
refreshing and then I can to XML HTTP Request but it's not supported well
with browsers. Any help here would be appreciated...

 
Thanks,
Stephen Craton
http://www.melchior.us

-----Original Message-----
From: Justin Patrin [mailto:papercranegmail.com]
Sent: Thursday, June 24, 2004 5:28 PM
To: Stephen Craton
Cc: PHP List
Subject: Re: [PHP] Streaming

It will use up CPU time and bandwidth, yes. It should take less bandwidth
than the "refresh constantly" version, but only if you code it right.

You could also write a little JS to pull some content from the server (get
messages after a certain time / message id) and inject them into the page.
This is really the best solution if you want to stay in the browser and not
do Flash or Java.

On Thu, 24 Jun 2004 17:24:31 -0500, Stephen Craton <webmastermelchior.us>
wrote:
>
> Thanks for all the help here.
>
> The only question I have left is bandwidth. Would a while(true) { }
> loop hog up enormous ammounts of bandwidth or just sit there quietly
bugging noone?
> The only other option I have going for me is the iframe hack, which
> I'm getting annoyed of...
>
> Thanks,
> Stephen Craton
> http://www.melchior.us
>
> -----Original Message-----
> From: Justin Patrin [mailto:papercranegmail.com]
> Sent: Thursday, June 24, 2004 5:01 PM
> To: Stephen Craton
> Cc: PHP List
> Subject: Re: [PHP] Streaming
>
> Your script is ending, so the page ends. PHP (HTTP) isn't really
> supposed to do "streaming." If you want it to "stream" you have to
> keep the script running. Add something like this:
>
> while(true) {
> while($db->next_record()) {
> echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> $sql = "SELECT emote, image FROM c_emotes";
> $result = mysql_query($sql, $db->linkid);
> while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> $emotes[] = $row['emote'];
> $images[] = "<img src='".$row['image']."'>";
> }
> if($db->Record['system'] != 1) {
> $message = htmlentities($db->Record["text"]);
> } else {
> $message = $db->Record["text"];
> }
> $message = str_replace($emotes, $images, $message);
> echo $message."<br>\n";
> flush();
> }
> sleep(5);
> set_time_limit(30);
> }
>
> This will actually run *forever* and will loop through the records
> again and again, probably giving yu the same content as before. You
> would need some kind of way to know which records are "new" so you can
> only display them in the loop. I would suggest adding a "time >
> $savedTime" or some such to the loop.
>
> Please note, though, that this is a *very large hack*. You're not
> supposed to keep your scripts running forever. If you really want to
> "stream", write a Java/C/C++/C#/etc. app. Or, if you're feeling
adventurous, use JavaScript.
>
> On Thu, 24 Jun 2004 16:54:57 -0500, Stephen Craton
> <webmastermelchior.us>
> wrote:
> >
> > I just put it into my script, and it doesn't seem to be working. I
> > put ob_end_clean(); at the top of the script, but here's the while
> > loop I
> have:
> >
> > while($db->next_record()):
> > echo '<b>'.$db->Record["user"].':</b>&nbsp;&nbsp;';
> > $sql = "SELECT emote, image FROM c_emotes";
> > $result = mysql_query($sql, $db->linkid);
> > while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> > $emotes[] = $row['emote'];
> > $images[] = "<img src='".$row['image']."'>";
> > }
> > if($db->Record['system'] != 1) {
> > $message = htmlentities($db->Record["text"]);
> > } else {
> > $message = $db->Record["text"];
> > }
> > $message = str_replace($emotes, $images, $message);
> > echo $message."<br>\n";
> > flush();
> > endwhile;
> >
> > It displays just fine if you refresh, but unless you refresh, you
> > don't see any new data. Any ideas?
> >
> > Thanks,
> > Stephen Craton
> > http://www.melchior.us
> >
> >
> >
> > -----Original Message-----
> > From: Justin Patrin [mailto:papercranegmail.com]
> > Sent: Thursday, June 24, 2004 4:47 PM
> > To: Stephen Craton
> > Cc: PHP List
> > Subject: Re: [PHP] Streaming
> >
> > ob_end_clean() goes at the top.
> > flush() goes after *every* pice of info you want to show real-time.
> > Basically, after every echo or group of echos.
> >
> > On Thu, 24 Jun 2004 16:43:39 -0500, Stephen Craton
> > <webmastermelchior.us>
> > wrote:
> > >
> > > Thanks for this, but how do I use it? Do I just put the
> > > ob_end_clean() at the opening the page I want to stream and then
> > > put
> flush() at the end?
> > >
> > > Thanks,
> > > Stephen Craton
> > > http://www.melchior.us
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: svk [mailto:svkksearch.f2o.org]
> > > Sent: Thursday, June 24, 2004 4:25 PM
> > > To: php-generallists.php.net
> > > Subject: Re: [PHP] Streaming
> > >
> > > On Thu, 2004-06-24 at 16:41, Stephenpp
> > >
> > > To use "streaming", you have to :
> > > Turn off output buffering: ob_end_clean() and flush the output has
> > > it comes
> > > : flush()
> > >
> > > It is useful to note that :
> > > "Some versions of Microsoft Internet Explorer will only start to
> > > display the page after they have received 256 bytes of output, so
> > > you may need to send extra whitespace before flushing to get those
> > > browsers to
> > display the page.
> > > "
> > >
> > > and
> > > "Pad your output with necessary spaces, wrap your progressing data
> > > around open (<table>) and end (</table>) tags, and then call
> > > flush() so that one script will work for Netscape as well.
> > > "
> > >
> > > > I was browsing the net and I found a PHP chat script that
> > > > claimed that it does not refresh, rather it has "streaming
> > > > text". This got my interest and was wondering how the script did
> > > > it. I downloaded it's source code but couldn't find anything
> > > > useful in it, very hard to read in my opinion. I did a search on
> > > > PHP.net for streaming but I couldn't understand much of that,
> > > > just my noobishness
> I suppose.
> > > >
> > > > How exactly would you go about streaming in PHP anyway? This has
> > > > my interest now...
> > > >