如何用PHP中的CGI服务器作为客户端进行通信?

With PHP I need to send a request to a CGI server, and then to receive the respective response. What I have done so far seems right until the moment of trying to read the response:

<?php
$request_body = '-----------------9022632e1130lc4
';
$request_body .= 'Content-Disposition: form-data; name="rutSender"
';
...
$request_body .= '</EnvioDTE>
';
$request_body .= '
';
$request_body .= '-----------------9022632e1130lc4--
';

$request = 'POST /cgi_dte/UPL/DTEUpload HTTP/1.0
';
$request .= 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/ms-excel, application/msword, */*
';
...
$request .= '
';
$request .= $request_body;

$hostName = 'host.name.example';
$host = gethostbyname($hostName);
$port = 443;

$fp = fsockopen($hostName, $port);
fwrite($fp, $request);

Below I try to read the response, but I receive "Fatal error: Maximum execution time of 120 seconds exceeded":

while(!feof($fp)){
    echo fgets($fp, 1024);
}
?>

As I am novice working with this kind of communication methods, it seems to me that in the PHP world exist way many options to try for solving this ploblem, like diverse socket functions, extensions and libraries (not that I have not tryed for 4 days)... I am confused and need orientation.

Regards

You need 2 newlines after request, not just the one you have. Try adding " " to the end of the request.

$request .= $request_body."
";

As a side note, you shouldn't have to bother with all that. Just use Curl and posting becomes 500% easier.