[Freeswitch-users] ESL, phpmod

Helmut Kuper helmut.kuper at ewetel.de
Thu Jun 17 00:07:53 PDT 2010


Hi Samuel,

unfortunately I haven't, yet. I found that the "new_ESLconnection
function doesn't like a php resource as  parameter like a socket, but
rather a file descriptor like a numeric pointer. Unfortunately I have no
idea how to convert a socket to such a file descriptor in php. Maybe
there is a function in the socket object but I don't think so.


So far as we didn't solve this problem here, I using my own php
functions to read and write from/to incomming connections from
freeswitch like this:


function fs_send($csock, $cmd)
{
        if (strlen($cmd) < 1) {
                acd_log(LOG_ERR, "Empty command\n");
                return false;
        }
        $clen=strlen($cmd);
        if ($bytes_written = socket_write($csock, "$cmd\n\n", $clen) ===
false) {
                acd_log(LOG_ERR, "Can't send cmd! Wrote $bytes_written
bytes\n");
                socket_write($csock, "\n\n");
                return false;
        }

        return true;
}


function fs_recv($csock, &$rbuf)
{
        $i=0;
	$buf="";
        do {
                acd_log(LOG_DEBUG, "Reading from socket '$csock'.\n");
                if (($tbuf = socket_read($csock, 10000)) === false) {
                        acd_log(LOG_ERR, "Can't read from client socket!
(".socket_last_error($csock)."/".socket_strerror(socket_last_error($csock)).")\n");
                        return false;
                }
                acd_log(LOG_DEBUG, "Read ".strlen($tbuf)." bytes from
socket '$csock'.\n");

                $buf .= $tbuf;
                $i++;
        } while (substr($buf, -2) != "\n\n" and $i <10);

        foreach (explode("\n", $buf) as $t) {
                list($key, $val) = explode(": ", $t);
                $rbuf[strtolower($key)]=$val;
        }

        return true;
}

acd_log() is just my own logging functions. you can replace it with
echo() or so.

You can build on this functions more abstract functions like
fs_connect(), fs_sendRecv(), ...

The command format is as described on FS wiki
(http://wiki.freeswitch.org/wiki/Event_socket_outbound)


That works quite good, but using the phpmod for esl would be more easy..


regards
Helmut


On 17.06.2010 03:50, Samuel Macedo wrote:
> Hi Helmut,
> 
> I got the same error:
> "No matching function for overloaded 'new_ESLconnection' in
> /usr/share/php/ESL.php"
> 
> Have you solved the problem?
> 
> Thanks,
> --
> Samuel Macedo
> 
> On 12 June 2010 14:59, Helmut Kuper <helmut.kuper at ewetel.de> wrote:
> 
>>  Hi Michael,
>>
>> ESL is built and installed, phpmod is built and installed.
>>
>> inbound works, test scripts works
>>
>> It is just the problem of passing an existing socket to new ESLconnection.
>> A socket resource is denied, an integer is accepted but is rejected with
>> "bad file descriptor"
>>
>>
>>
>> Am 12.06.2010 07:06, schrieb Michael Collins:
>>
>> Make sure the ESL is properly built and that the PHP mod is built and
>> installed. If you did a "make current" recently the you'll need to rebuild
>> your ESL stuff.
>> -MC
>>
>> On Fri, Jun 11, 2010 at 5:12 PM, Helmut Kuper <helmut.kuper at ewetel.de>wrote:
>>
>>> Hello,
>>>
>>>
>>> I try to setup a php daemon which uses ESL.
>>>
>>> I run the sample php scripts successfully (inbound). Now I want to have
>>> it outbound to my php daemon socket.
>>>
>>> The forked child process which has to interact with incoming tcp
>>> connection from FS is started successfully. So in this state I have the
>>> client socket which I have to pass now somehow to ESLconnection I guess.
>>>
>>> FS ruby wiki gives this as an example:
>>>
>>> @con = ESL::ESLconnection.new(client_socket.fileno)
>>>
>>>
>>> In php I try this:
>>>
>>> $con = new ESLconnection($csock);
>>>
>>> As a result I got this error:
>>>
>>> PHP Fatal error:  No matching function for overloaded
>>> 'new_ESLconnection' in /usr/share/pear/ESL.php on line 117
>>>
>>>
>>> Any ideas?
>>>
>>> regards
>>> Helmut



More information about the FreeSWITCH-users mailing list