Salve, sto utilizzando uno script preso da php.net per fare l'upload di un file via socket...
Il problema è che quando il file è abbastanza grosso lo script richiede tantissimo tempo a creare gli headers!
Ho fatto alcuni test e la lunghezza dell'header arrivava ad essere anche lunga 4 MILIONI di caretteri!!! Varia a seconda del peso del file da uploadare...
Come posso risolvere?
Questo è il codice che uso:
Codice PHP:
        $remote_url "/cgi-bin/prova.cgi";
        
$remote_server "localhost";
       
// get the necessary data
       
$file_name $_FILES['upfile']['name'];    // the file
       
$tmp_name $_FILES['upfile']['tmp_name'];    // the file
       
$content_type $_FILES['upfile']['type'];    // the file mime type
       
       
srand((double)microtime()*1000000);
       
$boundary "---------------------".substr(md5(rand(0,32000)),0,10);
       
       
// Build the header
       
$header "POST $remote_url HTTP/1.0\r\n";
       
$header .= "Host: $remote_server\r\n";
       
$header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
       
// attach post vars
       
foreach($_POST AS $index => $value){
           
$data .="--$boundary\r\n";
           
$data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
           
$data .= "\r\n".$value."\r\n";
           
$data .="--$boundary\r\n";
       }
       

       
       
// and attach the file
       
$data .= "--$boundary\r\n";
       
$data .="Content-Disposition: form-data; name=\"upfile\"; filename=\"$file_name\"\r\n";
       
$data .= "Content-Type: $content_type\r\n\r\n";
       
$data .= "".implode(""file($tmp_name))."\r\n";
       
$data .="--$boundary--\r\n";
       
$header .= "Content-length: " strlen($data) . "\r\n\r\n";
                 
// Open the connection
        
$header.=$data;
                 
       
$fp fsockopen($remote_server80);
       
fputs($fp$header);
       
fclose($fp);