cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

remote server with automatic response

From: StephenB <sb1304_at_hotmail.com>
Date: Wed, 13 Feb 2008 23:17:46 -0000

Hello

I'm having issues with a remote server which automatically responds with results on connection, or when aditional information is sent. It's reminiscent of a telnet/mail server, but for EPP requests.

The issue is that the response can be caught using output buffering or writefunctions, but the only way to stop curl_exec from hanging is to set a timeout value. Not very neatm and sort of defeats the purpose of a fast curl library!

Is there any way of setting curl to exit properly or at least tell curl_exec that once it's caught the response to exit immediately. Effectively this is a eof issue?

Thanks

Stephen

Example code (the server is IP restricted):
1: returntransfer - writefunction
#!/usr/local/bin/php
<?php

function write_function($ch, $string){
        global $written;
        $written .= $string;
        return strlen($string);
}

$written = '';
$aliases = array("");
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "testbed-epp.nominet.org.uk");
curl_setopt($ch, CURLOPT_PORT, 8700);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'write_function');

$res = curl_exec($ch);

print "len[".strlen($written)."]\n";
print $written;

curl_close($ch);
exit;
?>

2 Output buffering...
#!/usr/local/bin/php
<?php

$res = '';
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "testbed-epp.nominet.org.uk");
curl_setopt($ch, CURLOPT_PORT, 8700);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

// grab response...
ob_start();
curl_exec($ch);
$res = ob_get_contents();
ob_end_clean();

print "len[".strlen($res)."]\n";
print $res;

curl_close($ch);
exit;

?>

Results
------
* About to connect() to testbed-epp.nominet.org.uk port 8700
* Trying 213.248.200.142... * connected
* Connected to testbed-epp.nominet.org.uk (213.248.200.142) port 8700
> POST / HTTP/1.1
Host: testbed-epp.nominet.org.uk:8700
Accept: */*
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

* Operation timed out with 889 out of -1 bytes received
* Closing connection #0
len[948]
´<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
  <greeting>
    <svID>Nominet EPP server testbed-epp.nominet.org.uk</svID>
    <svDate>2008-02-13T23:10:41Z</svDate>
    <svcMenu>
      <version>1.0</version>
      <lang>en</lang>
      <objURI>http://www.nominet.org.uk/epp/xml/nom-account-1.0</objURI>
      <objURI>http://www.nominet.org.uk/epp/xml/nom-domain-1.0</objURI>
      <objURI>http://www.nominet.org.uk/epp/xml/nom-contact-1.0</objURI>
      <objURI>http://www.nominet.org.uk/epp/xml/ns-1.0</objURI>
    </svcMenu>
    <dcp>
      <access><all/></access>
      <statement>
        <purpose><admin/><prov/></purpose>
        <recipient><ours/></recipient>
        <retention><indefinite/></retention>
      </statement>
    </dcp>
  </greeting>
</epp>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-02-14