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

curl-and-php

Re: How i can use curl option instead php fputs function?

From: azkar <azkar_at_hotbox.ru>
Date: Mon, 10 Mar 2003 20:52:43 +0300 (MSK)

Ok, sorry for long message:)

/* here is original code

function connectServer(&$fp)
{
        if(!($fp = fsockopen(REG_HOST, REG_PORT, $errno,
$errstr, 90)))
        {
                return -1;
        }
        socket_set_blocking($fp, TRUE);
        while(1)
        {
                $line = fgets($fp, 1);
                $result .= $line;
                if(ereg("</epp>$", $result))
                {
                        break;
                }
        }
        
        if(ereg("</greeting></epp>$", $result))
        {
                return 0;
        }else {
                return -1;
        }
}

function sendCommand($fp, $command)
{
        fputs($fp, $command);
        while(1)
        {
                $line = fgets($fp, 1);
                $result .= $line;
                if(ereg("</epp>$", $result))
                {
                        break;
                }
        }
        
        $myfile = fopen("abc.txt", "a");
//just log file for checking
                                         //
        fwrite($myfile, $command . "\n" . $result);
        fclose($myfile);
        return $result;
}

/* end of original code

/* my code with curl

function connectServer(&$fp)
{ $ch = curl_init();
        curl_setopt ($ch, CURLOPT_TIMEOUT, 90);
        curl_setopt ($ch, CURLOPT_URL,REG_HOST.":".REG_PORT);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_HEADER, 0);
        ob_start();
        $result=curl_exec ($ch);
        ob_end_clean();
        curl_close ($ch);

        if(ereg("</greeting></epp>$", $result))
        {
                return 0;
       if(ereg("</greeting></epp>$", $result))
        {
                return 0;
        }else {
                return -1;
}

/* end of my curl code

here is what's i got when server answer when i use function
connectServer():

/* answer from server

<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:iana:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iana:xml:ns:epp-1.0
epp-1.0.xsd">
<greeting>
<svID>Template Server</svID>
<svDate>%s</svDate>
<svcMenu>
<version>1.0</version>
<lang>en-US</lang>
<contact:svc xmlns:contact="urn:iana:xml:ns:contact-1.0"
xsi:schemaLocation="urn:iana:xml:ns:contact-1.0 contact-
1.0.xsd"/>
<host:svc xmlns:host="urn:iana:xml:ns:host-1.0"
xsi:schemaLocation="urn:iana:xml:ns:host-1.0 host-1.0.xsd"/>
<domain:svc xmlns:domain="urn:iana:xml:ns:domain-1.0"
xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-
1.0.xsd"/>
<svcsub:svc xmlns:svcsub="urn:iana:xml:ns:svcsub-1.0"
xsi:schemaLocation="urn:iana:xml:ns:svcsub-1.0 svcsub-
1.0.xsd"/>
</svcMenu>
</greeting>
</epp>

then for logging i need send login command in follows format:

/* login command formatted as xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp>
<command>
<creds>
<clID>135617</clID>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
</creds>
<clTRID>L147481028182940_0</clTRID>
<login><chksum>9c4175211a307ee384bc2a13fbe0e4af</chksum></log
in>
</command>
</epp>

i send this command by original function sendCommand($fp,
$command) where as $command i use above login command.
When i send this command i have answer from server, like
above greetings message.

And here i am stopped, because i can't found any way how i
use may using curl here.

On my hosting i have following software installed:
curl 7.10.3 (i686-pc-linux-gnu) libcurl/7.10.3
OpenSSL/0.9.6b zlib/1.1.3

And i already check - yes, i can use curl from command line.

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-03-10