Hi. My proxy works with most sites, but a few sites like to return some garbage along the way. The garbage usually being either (at a guess) the content length, or in the case of google, something along the lines of be9. There is also a 0 added on to the end of each page.

Source: http://kevscomputer.selfip.org/files/proxy.phps

Any help or advice appreciated, I think the problem may be with the way it detects where the headers stop and the content begins.

    Your problem stems from the fact that you're implementing HTTP 1.1 incorrectly.

    The fact that you're implementing HTTP at all, should sound alarm bells. PHP already has a functional HTTP implemention built into it, and there are many others available as add-ons (several in PEAR, also curl).

    I'm not too sure what you're trying to achieve, but wouldn't you be better off with a conventional web proxy (e.g. squid) instead?

    Mark

      MarkR wrote:

      Your problem stems from the fact that you're implementing HTTP 1.1 incorrectly.

      So how should it be implemented?

      The fact that you're implementing HTTP at all, should sound alarm bells. PHP already has a functional HTTP implemention built into it, and there are many others available as add-ons (several in PEAR, also curl).

      Then why write anything? Also I wasn't aware PHP had built in HTTP support, please point it out to me.

      I'm not too sure what you're trying to achieve, but wouldn't you be better off with a conventional web proxy (e.g. squid) instead?

      No, that would defeat the whole point.

        do a google search on curl. It's like 50% faster

          foyer wrote:

          do a google search on curl. It's like 50% faster

          Why do a Google search. Just go to www.php.net/curl .

            because a google search will show you that page

              Translation: Neither of you know what you are talking about and are using pre-made scripts by someone else.

              I'll take my queries to people who have a clue.

                Why don't you take your queries to the book store and do some reading..

                No but really why do you say we have no idea what we are talking about.

                  foyer wrote:

                  Why don't you take your queries to the book store and do some reading..

                  Traditionally people go to a book store to buy books not read them.

                  No but really why do you say we have no idea what we are talking about.

                  Because you are unable to properly answer any of my questions, you just have some vague idea, all thanks to using pre-made scripts.

                  And in my own research, I found the difference between writing sockets and using curl random. i.e sometimes fsockopen is faster, sometimes curl is. But the difference is always < 1/4 second. Oh, there is another reason that you have no idea what you are talking about.

                    Well sorry my answer isn't good enough for you.. just trying to point you into a direction to try.

                    Oh and as a rule of thumb, it's generally a good idea to read (aka glance over) a book before you buy it. Or maybe it's just me.

                      Kevin 0 wrote:

                      there is another reason that you have no idea what you are talking about

                      You come here for help and when people try and help you then you tell them they're idiots. Not a way I'd ask for help!

                      I'm sure someone here knows the perfect answer to your question.
                      But with your attitude I think they should keep it to themselves.

                      THREAD LOCKED
                      (I wish 😉)

                        rowanparker wrote:

                        You come here for help and when people try and help you then you tell them they're idiots

                        Okay.....

                        So I ask for help, and someone says It's 'because I implemented HTTP1.1 wrong', even though it works for every site I tried, bar two. He offers no advice of how to do it right then says that implementing HTTP in PHP should ring alarm bells, for whatever reason. He then suggests using cURL or some sort of PEAR package (which would more than likely be written in PHP anyway!).

                        So I explain curl/PEAR is not an option.... Next few posts: Use curl.

                        Is there anyone here who actually writes proper scripts? Not just using other peoples?

                          Kevin 0 wrote:

                          Is there anyone here who actually writes proper scripts? Not just using other peoples?

                          Better attitude, but still. Why reinvent the wheel?

                            rowanparker wrote:

                            Better attitude, but still. Why reinvent the wheel?

                            Because I want to learn the how to do it mainly. My question was not I want a proxy, it was how to write a simple one.

                              Then maybe someone who knows more about the protocol will pop along and help you.

                                Kevin 0 wrote:

                                It's 'because I implemented HTTP1.1 wrong', even though it works for every site I tried, bar two.

                                I said that, and it's true. Read the RFC for HTTP 1.1 and you'll understand why it's wrong.

                                Get a network analyser on the job. Your script does not correctly handle chunked responses, which the HTTP 1.1 RFC says it is REQUIRED to do so. If your application cannot handle correct HTTP 1.1 responses, it should not send HTTP 1.1 requests.

                                Most web servers don't send chunked responses all of the time (after all, they're not required to) but some do.

                                READ THE RFC.

                                He offers no advice of how to do it right then says that implementing HTTP in PHP should ring alarm bells, for whatever reason. He then suggests using cURL or some sort of PEAR package (which would more than likely be written in PHP anyway!).

                                I give you three options:

                                1. Use PHP's built-in http client (see the fopen wrappers section of the manual for more information) which is functional enough for most applications, and far more correct than yours.
                                2. Use curl, which is more complicated to use and not always available, but provides greater functionality. Personally I haven't performance tested them so I'm not going to comment on runtime performance.
                                3. Use a third party module, e.g. from PEAR which implements HTTP. There are several of these, I have never used any of them.

                                The first option involves no external modules or nonstandard parts of PHP, and should be your first choice (in my opinion)

                                So I explain curl/PEAR is not an option.... Next few posts: Use curl.

                                Is there anyone here who actually writes proper scripts? Not just using other peoples?

                                I write all my own scripts and never use other peoples'. I find them inferior. In the cases where I have used third party stuff (e.g. Wordpress) I've found them horrendous and unmaintainable.

                                Mark

                                  Write a Reply...