NYCPHP Meetup

NYPHP.org

[nycphp-talk] can i replace curl with sockets?

Jim Musil jim at nettmedia.com
Wed Jan 29 15:21:44 EST 2003


I use a self-modified version of a script called PostIt which I think uses
sockets.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=15&lngWI
d=8

Jim

On 1/29/03 3:16 PM, "Mark Armendariz" <nyphp at enobrev.com> wrote:

> To start, I'm new to the list, so hello all.
> 
> I'm working on a script that requires cURL, but I'd rather surpass the
> need for cURL as it isn't usually installed by default on servers
> (namely mine - but other servers I've been on hadn't had it installed
> either).  I realize I could try to use the command line cURL, but it's
> my understanding that that can be a security issue, and I would just
> like to handle it all within the script.
> 
> I want to mimic this :
> ------------------------------
> 
> $curl_holder = curl_init();
> curl_setopt ($curl_holder , CURLOPT_URL, <https://k> '
> <https://www.url.com/script/> https://www.url.com/');
> curl_setopt ($curl_holder , CURLOPT_HEADER, 0);
> curl_setopt ($curl_holder , CURLOPT_POST, 1);
> curl_setopt ($curl_holder , CURLOPT_POSTFIELDS, $vars);
> curl_setopt ($curl_holder , CURLOPT_RETURNTRANSFER, 1);
> 
> $server_response = curl_exec ($curl_holder );
> curl_close ($curl_holder );
> 
> print $server_response;
> 
> I've tried this:
> -----------------
> 
>  $vars = 'name=mark&user=enobrev'
> 
>  $header = 'POST /track HTTP/1.0' . "\\r\
";
>  $header .= 'Content-type: application/x-www-form-urlencoded' .
> "\\r\
";
>  $header .= 'Content-length: ' . strlen($vars) . "\\r\
\\r\
";
> 
>  $fp = fsockopen('www.url.com/script/', 443, $error_number,
> $error_sting);
>  
>  if ($fp) {
>    fputs($fp, $header . $vars);
>    
>   while (!feof($fp)) {
>     $response .= fgets($fp, 128);
>     fclose($fp);
>   }
>   
>   print htmlspecialchars($response);
>  } else {
>   print $error_number . ': ' . $error_sting . ' - could not connect to
> ' . $url);
>  }
> 
> And i get a whole bunch of these (which refers to the while line and the
> lines within the loop):
> --------------------
> 
> Warning: feof(): 2 is not a valid File-Handle resource
> 
> The Question
> -------------------
> 
> Am I going the right way about this, or is there a better way?  And what
> exactly is that error referring to?
> 
> 
> Thank you in advance.
> 
> Mark Armendariz
> http://www.enobrev.com
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 




More information about the talk mailing list