Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-20 Thread Robert Cummings
On Sat, 2003-09-20 at 02:02, Curt Zirzow wrote:
 hmm.. on second thought...
 
 * Thus wrote Robert Cummings ([EMAIL PROTECTED]):
  [...]
  if( ($char = fread( $stdin, 1 )) !== false )
 
 How are you calling this script?  I'm not sure how cgi will handle
 fread stdin
 
 With a traditional CGI script stdin is what is read on POST data
 from a form, and php takes care of this.
 
 That is where my confusion is now.

I'm calling it as php -qC foo.php. The fread() should work since it
works on input when I don't have stdin in non-blocking mode. Perhaps
it's a bug. I took a look at the doc on streams again, and it uses
php://input as the POST stream. Maybe it's a bug.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-20 Thread Robert Cummings
On Sat, 2003-09-20 at 01:53, Dan Anderson wrote:
 I find your responses to my e-mails quite humorous.  Upon review --
 aside from a single WTF -- I don't think I was condescending in any way
 shape or form.  I was just trying to offer help.

The particular shape of your help was non newbie friendly. I think that,
combined with your incorrect assessments made it all the more annoying.
And yes, WTF and you really need to read the documentation played a
key part also since they were quite condescending, and inappropriate
given your incorrect answers and knowledge of functionality.

 After reading about wrappers, I find it doubly humorous that you didn't
 just disregard my e-mail when I asked you why you were using php://. 
 It's not like I said: php:// isn't a valid protocol.  http://; and
 ftp://; are all PHP supports.  I just said Why are you using php://
 below?
 
 And I also qualified my statements about fsockopen() and
 set_stream_blocking by saying I seem to remember and If I remember
 correctly.  And, yes, in PHP 3.0 or whatever it was that was true. 
 Hence the if I remember.

Yes a lovely weasel statement if ever I saw one.

 
 So, it would seem to me that as soon as you got to the WTF you should
 have said, This guy thinks I am a noob.  And at that point you should
 have just said thanks but you're wrong. 

Actually at that point I thought, this guy thinks I'm an noob and he's
being an arse about it. That's no way to treat noobs that post
appropriate questions.

 And, just for the record, you never explicitly stated that you needed a
 reason to read in only one character at a time.  You just sent a bunch
 of code down the pipe.  So it seems quite natural to assume you're just
 making a noobish mistake -- reading a char at a time when a string will
 do.

I certainly explained quite well what the problem was. And as you
assumed I was making a noobish mistake and sent a scathing response to
my problem, I also assumed you were an ass, and needed some kind of
clarification.

 Anyways, you are running an infinite loop and I don't quite see how this
 is exiting:

YES, this is the original question. Why is it exiting. To which you gave
me a whole set of unrequested answers that weren't even on the topic of
my post.

 while (1) 
 {
 if ()
 else
 }
 
 But, hey, more power to you if you've gotten to the level where you
 don't understand why people who don't understand some esoteric function
 are such muppets.

If you don't understand the function, then why are you posting answers
as though you do? Someone asks me about quantum physics, I don't pretend
to know and confuse the whole issue.

 
 BTW: If you insist on keeping up with the flamethrowers kindly e-mail me
 off list so as not to bother others on the listserv.

Yes, if you reply I'll be sure to take the next one off list, but since
you made this public, I'm sure readers would love to see the backdraft.
The above statement is actually an underhanded attempt to get the last
public word while preventing me from a public response. If you were so
keen to have it off the list, then this email I'm responding to, should
have been off-list itself.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-20 Thread Eugene Lee
On Sat, Sep 20, 2003 at 02:14:54AM -0400, Robert Cummings wrote:
: On Sat, 2003-09-20 at 01:53, Dan Anderson wrote:
: 
:  I find your responses to my e-mails quite humorous.  Upon review --
:  aside from a single WTF -- I don't think I was condescending in any way
:  shape or form.  I was just trying to offer help.
: 
: The particular shape of your help was non newbie friendly. I think that,
: combined with your incorrect assessments made it all the more annoying.
: And yes, WTF and you really need to read the documentation played a
: key part also since they were quite condescending, and inappropriate
: given your incorrect answers and knowledge of functionality.
[...snips snipped...]

Can't we just get along and bash M$ ?  Or VeriSign ?  :-)

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-20 Thread Marek Kilimajer
File a bug report. stream_set_blocking() started to work for files only 
since version 4.3, so it is likely full of bugs. Actualy, using cli php 
4.3.2 I got this results some weird results. Your version run infinitely 
but changing echo 'Fooo!'.\n; to echo 'Fooo!'; (removing newline) 
resulted in the same behavior as you experienced. fread did not return 
false even if no key was pressed, only empty string but this might be 
correct, i don't know. Both fgetc and fgets did return false.

Robert Cummings wrote:

On Sat, 2003-09-20 at 02:02, Curt Zirzow wrote:

hmm.. on second thought...

* Thus wrote Robert Cummings ([EMAIL PROTECTED]):

[...]
   if( ($char = fread( $stdin, 1 )) !== false )
How are you calling this script?  I'm not sure how cgi will handle
fread stdin
With a traditional CGI script stdin is what is read on POST data
from a form, and php takes care of this.
That is where my confusion is now.


I'm calling it as php -qC foo.php. The fread() should work since it
works on input when I don't have stdin in non-blocking mode. Perhaps
it's a bug. I took a look at the doc on streams again, and it uses
php://input as the POST stream. Maybe it's a bug.
Cheers,
Rob.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Dan Anderson
Why are you using php:// below?  If stdin is a file './stdin' will
suffice (or the path instead of ./).  If you want to run the PHP script
in stdin you should use one of the following:
include()
include_once()
require()
require_once()
See the manual at php.net for pertinent sections...
 if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
 { 
 echo 'Failed to open STDIN'.\n;
 exit();
 }  

I seem to remember stream_set_blocking being either experimental or deprecated.
If I remember correctly its for use with the function fsock_open().
 stream_set_blocking( $stdin, false );
  
 $count = 0;  
WTF are you thinking?  You really need to read the documentation. 
Instead of this:
 while( 1 ) 
 { 
 echo 'Foo: '.($count++).\n;
 if( ($char = fread( $stdin, 1 )) !== false )
 {
 echo $char.\n;
 }
 else
 {
 echo 'Fooo!'.\n;
 }
 }

Try:

?php

$stdin = fopen(./stdin,r);
while ($stdin AND (!(feof($stdin
{ echo fread($stdin,4096); }

?

Much simpler, correct?

BTW: The infinite loop you have above could be the reason your script is
acting erratically.  PHP kills off scripts after they run for so long --
you may just be catching it in different versions of the loop.

Also BTW: I understand what you mean when you say CGI but not CLI
version of PHP, but I really don't think the term CGI applies in this
case.  CGI means Common Gateway Interface -- or a way to execute
programs in a special directory designed to keep them from r00ting the
system.  In PHP things such as headers are automatic -- no need to type:

print Content-type: text/html\n\n;

It's a server side scripting language designed to be embedded in things
like web pages and be able to be run without much security concerns. 
(i.e. not running a CGI perl scrip as /usr/bin/perl (i.e. not in tainted
mode) -- ouch!  and these are the silly things users sometimes do)

-Dan

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Dan Anderson
One more thing:

gdb doesn't do a damned thing for debugging PHP scripts.  Look for the
errors and warnings output to the browser.  (or tty if you're using
/usr/bin/php).  

-Dan

On Sat, 2003-09-20 at 00:33, Robert Cummings wrote:
 I wanted t play around with the CGI (not CLI) version of PHP and get a
 feel for the I/O stuff, specifically STDIN. So I whipped up the
 following script:
 
 ///
 
 #!/usr/bin/php -qC
 ?
   
 if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
 { 
 echo 'Failed to open STDIN'.\n;
 exit();
 }  
  
 stream_set_blocking( $stdin, false );
  
 $count = 0;  
 while( 1 ) 
 { 
 echo 'Foo: '.($count++).\n;
 if( ($char = fread( $stdin, 1 )) !== false )
 {
 echo $char.\n;
 }
 else
 {
 echo 'Fooo!'.\n;
 }
 }
 
 
 
 Simple enough right?! The problem is the program exits seemingly
 randomly. The last value for $foo can be anywhere from 400 to 1500. Even
 more strange is that running it through gdb indicates a successful exit,
 with no problems or core dumps. Anyone had any similar experiences? I'm
 running PHP 4.3.3 (cgi) -- the latest download version.
 
 Cheers,
 Rob.
 -- 
 ..
 | InterJinn Application Framework - http://www.interjinn.com |
 ::
 | An application and templating framework for PHP. Boasting  |
 | a powerful, scalable system for accessing system services  |
 | such as forms, properties, sessions, and caches. InterJinn |
 | also provides an extremely flexible architecture for   |
 | creating re-usable components quickly and easily.  |
 `'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Robert Cummings
On Sat, 2003-09-20 at 00:59, Dan Anderson wrote:
 Why are you using php:// below?  If stdin is a file './stdin' will

Because it is the correct way to retrieve input from standard input.

http://www.php.net/wrappers.php

 suffice (or the path instead of ./).  If you want to run the PHP script
 in stdin you should use one of the following:
 include()
 include_once()
 require()
 require_once()
 See the manual at php.net for pertinent sections...

I don't want to run a script from stdin, I want to retrieve user input
from the keyboard. What the heck are you smoking?

  if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
  { 
  echo 'Failed to open STDIN'.\n;
  exit();
  }  
 
 I seem to remember stream_set_blocking being either experimental or deprecated.
 If I remember correctly its for use with the function fsock_open().
  stream_set_blocking( $stdin, false );

No stream_set_blocking() is the correct function. The others are
deprecated because they are less generic for streams:

This function was previously called as set_socket_blocking()
and later socket_set_blocking() but this usage is deprecated.

  $count = 0;  
 WTF are you thinking?  You really need to read the documentation. 
 Instead of this:

You sir, are a moron, you are calling me a moron and yet you are the one
who doesn't know what you are talking about.

  while( 1 ) 
  { 
  echo 'Foo: '.($count++).\n;
  if( ($char = fread( $stdin, 1 )) !== false )
  {
  echo $char.\n;
  }
  else
  {
  echo 'Fooo!'.\n;
  }
  }
 
 Try:
 
 ?php
 
 $stdin = fopen(./stdin,r);
 while ($stdin AND (!(feof($stdin
 { echo fread($stdin,4096); }
 
 ?
 
 Much simpler, correct?

This is not what I want, I want individual keystrokes as they come in
form the keyboard. I'm quite sure I know what I'm doing.

 BTW: The infinite loop you have above could be the reason your script is
 acting erratically.  PHP kills off scripts after they run for so long --
 you may just be catching it in different versions of the loop.

Infinite loop, shmoop, the script ran for less than a second. Long
enough for $count to get as high as 2000 tops. I've run many, MANY
scripts as CGI shell script, and never has it bailed from an infinite
loop successfully in less than a second.

 Also BTW: I understand what you mean when you say CGI but not CLI
 version of PHP, but I really don't think the term CGI applies in this
 case.  CGI means Common Gateway Interface -- or a way to execute
 programs in a special directory designed to keep them from r00ting the
 system.  In PHP things such as headers are automatic -- no need to type:

I use the term CGI for the mode in which PHP was compiled, NOT, AND I
REPEAT NOT, because I'm using it as a Common Gateway interface.

 print Content-type: text/html\n\n;
 
 It's a server side scripting language designed to be embedded in things
 like web pages and be able to be run without much security concerns. 
 (i.e. not running a CGI perl scrip as /usr/bin/perl (i.e. not in tainted
 mode) -- ouch!  and these are the silly things users sometimes do)

Thanks for the lesson, I'll be sure to pretend I didn't know what CGI
is. BTW, if I were a newbie at PHP, your message would make me never
want to make another post. Even in the event you are correct, such a
pathetic response is no way to treat those of lesser knowledge. Now go
read the docs, and learn some more before trying to tell me what's what.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Robert Cummings
On Sat, 2003-09-20 at 01:01, Dan Anderson wrote:
 One more thing:
 
 gdb doesn't do a damned thing for debugging PHP scripts.  Look for the
 errors and warnings output to the browser.  (or tty if you're using
 /usr/bin/php).  

Oh you had to tie another on on. I guess I look really stupid. Hmmm
maybe I forgot to run gdb on the PHP binary instead of on the script. Oh
yes, that's got to be it. I ran gdb on the script, and once again I'm
stupid. Now I'm off to say a prayer that you don't inundate me with more
crap.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Curt Zirzow
* Thus wrote Robert Cummings ([EMAIL PROTECTED]):
 I wanted t play around with the CGI (not CLI) version of PHP and get a
 feel for the I/O stuff, specifically STDIN. So I whipped up the
 following script:
 
 ///
 
 #!/usr/bin/php -qC
 ?
   
 if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
 { 
 echo 'Failed to open STDIN'.\n;
 exit();
 }  
  
 stream_set_blocking( $stdin, false );

I believe this is not needed, stdin is nonblocking all the time.

  
 $count = 0;  
 while( 1 ) 

this will never exit until php runs out of memory, and most likely
will lead to unexpected results.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Robert Cummings
On Sat, 2003-09-20 at 01:52, Curt Zirzow wrote:
 * Thus wrote Robert Cummings ([EMAIL PROTECTED]):
  I wanted t play around with the CGI (not CLI) version of PHP and get a
  feel for the I/O stuff, specifically STDIN. So I whipped up the
  following script:
  
  ///
  
  #!/usr/bin/php -qC
  ?

  if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
  { 
  echo 'Failed to open STDIN'.\n;
  exit();
  }  
   
  stream_set_blocking( $stdin, false );
 
 I believe this is not needed, stdin is nonblocking all the time.

My original test script didn't set the blocking state to non blocking. I
determined from that that stdin is initally in a blocking state. Since I
typed several characters and none where printed till I hit enter.

 
   
  $count = 0;  
  while( 1 ) 
 
 this will never exit until php runs out of memory, and most likely
 will lead to unexpected results.

Yeah, it was just a test script. But still, if the memory had been
exhausted, it wouldn't be in under a second, and I'd get a core dump
like I usually do when I have a runaway recursive function.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Dan Anderson
I find your responses to my e-mails quite humorous.  Upon review --
aside from a single WTF -- I don't think I was condescending in any way
shape or form.  I was just trying to offer help.

After reading about wrappers, I find it doubly humorous that you didn't
just disregard my e-mail when I asked you why you were using php://. 
It's not like I said: php:// isn't a valid protocol.  http://; and
ftp://; are all PHP supports.  I just said Why are you using php://
below?

And I also qualified my statements about fsockopen() and
set_stream_blocking by saying I seem to remember and If I remember
correctly.  And, yes, in PHP 3.0 or whatever it was that was true. 
Hence the if I remember.

So, it would seem to me that as soon as you got to the WTF you should
have said, This guy thinks I am a noob.  And at that point you should
have just said thanks but you're wrong. 

And, just for the record, you never explicitly stated that you needed a
reason to read in only one character at a time.  You just sent a bunch
of code down the pipe.  So it seems quite natural to assume you're just
making a noobish mistake -- reading a char at a time when a string will
do.

Anyways, you are running an infinite loop and I don't quite see how this
is exiting:

while (1) 
{
if ()
else
}

But, hey, more power to you if you've gotten to the level where you
don't understand why people who don't understand some esoteric function
are such muppets.

BTW: If you insist on keeping up with the flamethrowers kindly e-mail me
off list so as not to bother others on the listserv.

-Dan

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Curt Zirzow
hmm.. on second thought...

* Thus wrote Robert Cummings ([EMAIL PROTECTED]):
 [...]
 if( ($char = fread( $stdin, 1 )) !== false )

How are you calling this script?  I'm not sure how cgi will handle
fread stdin

With a traditional CGI script stdin is what is read on POST data
from a form, and php takes care of this.

That is where my confusion is now.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] Problem with getting non-blocking data from stdin

2003-09-19 Thread Curt Zirzow
* Thus wrote Dan Anderson ([EMAIL PROTECTED]):
 I find your responses to my e-mails quite humorous.  Upon review --

hmm... its almost (is) saturday lets all drop it.

cheers.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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