On 6/22/07, FrozenDice <[EMAIL PROTECTED]> wrote:
What do you mean not all the data is sent at once?  I'm doing a http
request, the browser responds sending back the code for the page.
I've never heard of it sending back multiple responses.  Plus I'm
controling what the server sends from the ISAPI code, I'm only sending
info back once.  I'm kinda confused on this whole not sending all the
data at once.

- Dan

That's just the way how our network works :)
HTTP is over TCP/IP.
TCP/IP sends data in packets, each package is max. 1500 bytes.
So, when your server sends a site of let's say 1200 bytes then all
data will be in one single packet. But when your site returned is more
then 1500 bytes, your site will be split across multiple packets.
Reading with fread stops after a package is available...
This is also noted in the second warning on the fread manual page[1].

Tijnema

ps. Please don't top post

pps. When you make reply, make sure you have the PHP list in your To:
or Cc:, most mail clients allow you to use "Reply to all" for this.

[1] http://www.php.net/fread



On 6/22/07, Tijnema <[EMAIL PROTECTED]> wrote:
> On 6/22/07, FrozenDice <[EMAIL PROTECTED]> wrote:
> > I came up with a what I presume to be quicker way of doing this by
> > knowing the format.  Since the headers always have \r\n after each
> > line, then a blank line before the content I made this little bit of
> > code.
> >
> >               $explodedResult = explode("\r\n", $result);
> >                for($i = 0; $i <= count($explodedResult); $i++)
> >                {
> >                        if($explodedResult[$i] == "")
> >                        {
> >                         return $explodedResult[($i + 1)];
> >                        }
> >                }
> >
> > - Dan
>
> Yes, it is faster, but sometimes, when loading big sites, not all data
> is send at once, and then you need to get the content-length from the
> header and read that many bytes. That's why i've written a little bit
> longer code :)
>
> Tijnema
> >
> > On 6/22/07, FrozenDice <[EMAIL PROTECTED]> wrote:
> > > I've read through that code a few times and I still don't understand
> > > at all what's going on.  Could you explain it?
> > >
> > > - Dan
> > >
> > > On 6/22/07, Tijnema <[EMAIL PROTECTED]> wrote:
> > > > On 6/20/07, Tijnema <[EMAIL PROTECTED]> wrote:
> > > > > On 6/19/07, Dan <[EMAIL PROTECTED]> wrote:
> > > > > > Whoops, it turned out just to be a line wrapping problem, it was 
putting an
> > > > > > extra space in.
> > > > > >
> > > > > > I have it working now, but after every request I get back the 
returning
> > > > > > header in my result to it looks like this:
> > > > > >
> > > > > > HTTP/1.1 200 OK
> > > > > > Content-Length: 184
> > > > > > Content-Type: text/html
> > > > > > Server: Microsoft-IIS/7.0
> > > > > > Content:
> > > > > > Date: Tue, 19 Jun 2007 17:20:04 GMT
> > > > > >
> > > > > > The resulting page I really wished to be returned.
> > > > > >
> > > > > > How do I get this not to set the return header in the $result?  Or 
shoudl I
> > > > > > just somehow get rid of the header after I get it?  I don't know 
how long it
> > > > > > is so I can't do a substring.  Ideas?
> > > > >
> > > > > It has to do something with the way the things are send across the
> > > > > internet, in packages. The manual of fread says that it will read
> > > > > until EOF, the given length or the end of a package...
> > > > >
> > > > > try this code:
> > > > > $post_data = "name=wow&likes=true";
> > > > > $fp = fsockopen("localhost",8080);
> > > > > fwrite($fp,"POST /Project1.dll
> > > > > 
HTTP/1.1\r\nHost:localhost\r\nContent-Length:".strlen($post_data)."\r\n\r\n".$post_data);
> > > > > $line = fgets($fp);
> > > > > $length = 0;
> > > > > while($line != "\r\n") {
> > > > > if(strtolower(substr($line,0,15)) == "content-length:") {
> > > > > $length = (int)substr($line,15);
> > > > > }
> > > > > }
> > > > > $result = fread($fp,$length);
> > > > > while(strlen($result) != $length) {
> > > > > $result .= fread($fp,$length-strlen($result));
> > > > > }
> > > > > echo $result;
> > > > >
> > > > > Ok, above code is untested, and i just written it in gmail, so might
> > > > > be stupid syntax error in it or such.
> > > > >
> > > > > Tijnema
> > > >
> > > > Like I said, there might be stupid bugs in, this code is better:
> > > > $post_data = "name=wow&likes=true";
> > > > $fp = fsockopen("localhost",8080);
> > > > fwrite($fp,"POST /Project1.dll
> > > > 
HTTP/1.1\r\nHost:localhost\r\nContent-Length:".strlen($post_data)."\r\n\r\n".$post_data);
> > > >
> > > > $line = fgets($fp);
> > > > $length = 0;
> > > > while($line != "\r\n") {
> > > > if(strtolower(substr($line,0,15)) == "content-length:") {
> > > > $length = (int)substr($line,15);
> > > > $line = fgets($fp);
> > > > }
> > > > }
> > > > $result = fread($fp,$length);
> > > > while(strlen($result) != $length) {
> > > > $result .= fread($fp,$length-strlen($result));
> > > > }
> > > > echo $result;
> > > > >
> > > > > >
> > > > > > ""Dan"" <[EMAIL PROTECTED]> wrote in message
> > > > > > news:[EMAIL PROTECTED]
> > > > > > >I modified your code to work with what I'm doing and this is what 
I got:
> > > > > > >
> > > > > > > $post_data = "name=wow&likes=true";
> > > > > > > $fp = fsockopen("localhost",8080);
> > > > > > > fwrite($fp,"POST /Project1.dll HTTP/1.1\r\nHost:
> > > > > > > localhost\r\nContent-Length:
> > > > > > > ".strlen($post_data)."\r\n\r\n".$post_data);
> > > > > > > $result = fread($fp,102400); // Reads 100KB, change if you need 
more
> > > > > > > echo $result;
> > > > > > >
> > > > > > > Now when I try that I get a "Bad Request invalid header name" 
error.
> > > > > > >
> > > > > > > I have an IIS server running localy on port 8080, the 
Project1.dll is in
> > > > > > > the root directory, it contains two input components 1 a 
textfield to type
> > > > > > > your name, the other a checkbox called likes.  What's wrong? 
Here's it's
> > > > > > > code:
> > > > > > >
> > > > > > > <html>
> > > > > > > <head>
> > > > > > > <title>Learning ISAPI</title>
> > > > > > > </head>
> > > > > > > <h3>Learning ISAPI!</h3>
> > > > > > > <form name="isapiform" method="POST" action="/Project1.dll">
> > > > > > > <strong>Please enter the following information</strong>
> > > > > > > <br>Name: <input type="text" name="name">
> > > > > > > <br><input type="checkbox" name="likes" value="true" checked> I 
like
> > > > > > > ISAPI!<p>
> > > > > > > <input type="submit" value="View Output">
> > > > > > > </form>
> > > > > > > </html>
> > > > > > >
> > > > > > > "Tijnema" <[EMAIL PROTECTED]> wrote in message
> > > > > > > news:[EMAIL PROTECTED]
> > > > > > >> On 6/19/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
> > > > > > >>> Dan wrote:
> > > > > > >>> > I wish I could, I can't count on the script being on a linux 
machine.
> > > > > > >>> > I
> > > > > > >>> > also can't expect people to rebuild PHP with the curl library 
just to
> > > > > > >>> > use my script.  Is there any other way to do a post to a page 
from a
> > > > > > >>> > php
> > > > > > >>> > function?
> > > > > > >>> >
> > > > > > >>> > - Daniel
> > > > > > >>> >
> > > > > > >>> > "Jim Lucas" <[EMAIL PROTECTED]> wrote in message
> > > > > > >>> > news:[EMAIL PROTECTED]
> > > > > > >>> >> Dan wrote:
> > > > > > >>> >>> I would normaly do it with an AJAX call but I need to do a 
post from
> > > > > > >>> >>> WITHIN a PHP function, so when it's doing php stuff
> > > > > > >>> >>> ex.
> > > > > > >>> >>> function something()
> > > > > > >>> >>> {
> > > > > > >>> >>> echo 'whatever';
> > > > > > >>> >>> $response = post some data to a ISAPI Extension eg. post to
> > > > > > >>> >>> http://domain.com/scripts/app.dll
> > > > > > >>> >>> return $response . "other data";
> > > > > > >>> >>> }
> > > > > > >>> >>>
> > > > > > >>> >>>
> > > > > > >>> >>> ""Jay Blanchard"" <[EMAIL PROTECTED]> wrote in message
> > > > > > >>> >>> news:[EMAIL PROTECTED]
> > > > > > >>> >>> [snip]
> > > > > > >>> >>> I'm in need of a way to contact an ISAPI Extension from a 
PHP
> > > > > > >>> >>> function.
> > > > > > >>> >>> Does anyone know how I would be able to do this?  Usually 
you would
> > > > > > >>> >>> post
> > > > > > >>> >>> a
> > > > > > >>> >>> page to their URL/actionname.  Can I do a POST from a PHP 
function
> > > > > > >>> >>> without
> > > > > > >>> >>> reloading the page, and get a result back?  That's one tall 
order.
> > > > > > >>> >>> Anyone
> > > > > > >>> >>> want to give it a shot?
> > > > > > >>> >>> [/snip]
> > > > > > >>> >>>
> > > > > > >>> >>> Do the POST with an AJAX call
> > > > > > >>> >>
> > > > > > >>> >> perform an ajax call the a php script that calls curl to do 
a post to
> > > > > > >>> >> the ISAPI extension
> > > > > > >>> >>
> > > > > > >>> >> --
> > > > > > >>> >> Jim Lucas
> > > > > > >>> >>
> > > > > > >>> >>    "Some men are born to greatness, some achieve greatness,
> > > > > > >>> >>        and some have greatness thrust upon them."
> > > > > > >>> >>
> > > > > > >>> >> Twelfth Night, Act II, Scene V
> > > > > > >>> >>     by William Shakespeare
> > > > > > >>> >
> > > > > > >>> The only method that I am aware of is the fsockopen method you 
mention
> > > > > > >>> in your other email
> > > > > > >>>
> > > > > > >>> --
> > > > > > >>> Jim Lucas
> > > > > > >>
> > > > > > >> Yes, and what's wrong with it?
> > > > > > >> <?php
> > > > > > >> $post_data = "form_a=1&form_b=4";
> > > > > > >> $fp = fsockopen("www.domain.com",80);
> > > > > > >> fwrite($fp,"POST /scripts/app.dll HTTP/1.1\r\nHost:
> > > > > > >> www.domain.com\r\nContent-Length:
> > > > > > >> ".strlen($post_data)."\r\n\r\n".$post_data);
> > > > > > >> $result = fread($fp,102400); // Reads 100KB, change if you need 
more
> > > > > > >> ?>
> > > > > > >>
> > > > > > >> That's not too long is it?
> > > > > > >>
> > > > > > >> Tijnema
> > > > > > >>>
> > > > > >
> > > > > > --
> > > > > > PHP General Mailing List (http://www.php.net/)
> > > > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
> > > >
> > >
> >
>
>
> --
> Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info
>



--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

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

Reply via email to