PHP 8.6.0 Alpha 2 available for testing

Voting

: max(five, seven)?
(Example: nine)

The Note You're Voting On

brage (a t) jeffnappi (d.o.t) commie
23 years ago
thought you guys may appreciate this function, allows you to pass an array of urls to download and does so simultaneously using non-blocking sockets, then returns the data in an array.
<?php
// function connects to an array of URLS at the same time
// and returns an array of results.
function multiHTTP ($urlArr) {
 $sockets = Array(); // socket array!
 $urlInfo = Array(); // info arr
 $retDone = Array();
 $retData = Array();
 $errno = Array();
 $errstr = Array();
 for ($x=0;$x<count($urlArr);$x++) {
 $urlInfo[$x] = parse_url($urlArr[$x]);
 $urlInfo[$x][port] = ($urlInfo[$x][port]) ? $urlInfo[$x][port] : 80;
 $urlInfo[$x][path] = ($urlInfo[$x][path]) ? $urlInfo[$x][path] : "/";
 $sockets[$x] = fsockopen($urlInfo[$x][host], $urlInfo[$x][port],
 $errno[$x], $errstr[$x], 30);
 socket_set_blocking($sockets[$x],FALSE);
 $query = ($urlInfo[$x][query]) ? "?" . $urlInfo[$x][query] : "";
 fputs($sockets[$x],"GET " . $urlInfo[$x][path] . "$query HTTP/1.0\r\nHost: " .
 $urlInfo[$x][host] . "\r\n\r\n");
 }
 // ok read the data from each one
 $done = false;
 while (!$done) {
 for ($x=0; $x < count($urlArr);$x++) {
 if (!feof($sockets[$x])) {
 if ($retData[$x]) {
 $retData[$x] .= fgets($sockets[$x],128);
 } else {
 $retData[$x] = fgets($sockets[$x],128);
 }
 } else {
 $retDone[$x] = 1;
 }
 }
 $done = (array_sum($retDone) == count($urlArr));
 }
 return $retData;
}
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /