Find Jobs
Hire Freelancers

how to know a remote webserver is finished, if it doesn't close the socket

$30-100 USD

În desfășurare
Data postării: circa 12 ani în urmă

$30-100 USD

Plata la predare
I have a simple PHP script that fetches content from remote websites. The problem is that some web servers, [login to view URL] for example, after sending the data for a page, they don't close the TCP connection, so web page download doesn't complete until the fread() call times out (after 60 seconds by default, although I can lower that with stream_set_timeout()). On the other hand, if I use curl to fetch the same page: curl [login to view URL] -o [login to view URL] the operation completes almost instantly. So here is exactly what I want to know: How does curl "know" that [login to view URL] is finished sending data (even though the server doesn't close the connection)? And how can I make my PHP script aware of that as well, so it doesn't have to wait for the connection to time out? With this simple php script for example: <?php $hostname = "[login to view URL]"; $_socket = @fsockopen("tcp://$hostname", 80); fwrite($_socket, "GET / HTTP/1.0\r\nHost: $hostname\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)\r\n\r\n"); do { $timebefore = time(); $data = @fread($_socket, 8192); $timeafter = time(); echo "fread from $hostname: " . ($timeafter-$timebefore) . " seconds for " . strlen($data) . " bytes\n"; } while (isset($data{0})); ?> if I run it, I get this output: [root@peacefire01 - /var/www/html # php [login to view URL] fread from [login to view URL]: 0 seconds for 2901 bytes fread from [login to view URL]: 0 seconds for 1467 bytes fread from [login to view URL]: 0 seconds for 1520 bytes fread from [login to view URL]: 0 seconds for 1780 bytes fread from [login to view URL]: 60 seconds for 0 bytes Notice the 60 seconds at the end. If, however, I replace "[login to view URL]" with "[login to view URL]" at the top, then the page downloads "normally" without a long timeout for the last fread() call.
ID-ul proiectului: 2730550

Despre proiect

O propunere
Proiect la distanță
Activ: 12 ani în urmă

Vrei să câștigi bani?

Avantajele de a licita pe platforma Freelancer

Stabilește bugetul și intervalul temporal
Îți primești plata pentru serviciile prestate
Evidențiază-ți propunerea
Te înregistrezi și licitezi gratuit pentru proiecte
Acordat utilizatorului:
Avatarul utilizatorului
See private message.
$15 USD în 14 zile
5,0 (99 recenzii)
5,5
5,5

Despre client

Steagul UNITED STATES
Bellevue, United States
5,0
128
Metoda de plată a fost confirmată
Membru din oct. 24, 2004

Verificarea clientului

Mulțumim! Ți-am trimis prin e-mail linkul pe care trebuie să-l accesezi pentru a revendica creditul gratuit.
A apărut o eroare la trimiterea e-mailului. Încearcă din nou.
Utilizatori înregistrați Totalul proiectelor postate
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Se încarcă previzualizarea
S-a oferit permisiunea de depistare a locației.
Ți-a expirat sesiunea pentru conectare sau te-ai deconectat. Conectează-te din nou.