Tek bir fsockopen ile birden çok sayfa olsun

0 Cevap php

Hy all. I need to get the content of multiple pages from a single domain. Now for each page I use an fsockopen connection, and I get the content of the page this way:

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET /page1.html HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        fgets($fp, 128);
    }
    fclose($fp);
}

>

My script wastes time, with reconnecting to the domain, to get the second page. I was wondering, if is possible to use a single connection, and to get multiple pages, like this:

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {

    $out = "GET /page1.html HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        fgets($fp, 128);
    } $out = "GET /page2.html HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        fgets($fp, 128);
    }
    fclose($fp);
}

>

Ancak bu yöntem sayfa1.html iki kez dönen, ben neden bilmiyorum.

Bağlantı: ben kullanmaya çalıştım canlı tutmak, ya da HTTP/1.0, ama bu durumda ben sunucudan (benim script sonsuz yürütme zamanı) bir şey alamadım.

Bu çözmek için herhangi bir öneri?

Teşekkür ederiz!

0 Cevap