NYCPHP Meetup

NYPHP.org

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

Mark Armendariz nyphp at enobrev.com
Wed Jan 29 15:19:15 EST 2003


Sorry, the CURLOPT_URL line got screwy:

  curl_setopt ($curl_holder , CURLOPT_URL, 'https://www.url.com/');

Mark

-----Original Message-----
From: Mark Armendariz [mailto:nyphp at enobrev.com] 
Sent: Wednesday, January 29, 2003 3:16 PM
To: NYPHP Talk
Subject: [nycphp-talk] can i replace curl with sockets?


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