Forums / Developer / how to: php socket comunication??

how to: php socket comunication??

Author Message

Alessandro Cipriani

Friday 16 April 2004 2:41:51 am

hi all
that's my problem:
in my pagelayout.tpl i got to make a call to a log server that will register some information i send to it but without opening any browser window.
i read some php documentation and i saw that there is the socket functions that will fit for me.
so i modified the templatestringoperator.php by adding a new function "sendviasocket" in this way:

//send a socket  request
case $this->SendViaSocket:
{
	/* get the port for the WWW service. */
	$service_port = getservbyname('www', 'tcp');
			
	/* get the server address. */
	$address = gethostbyname($namedParameters['address']);

         /*open the socket*/
	$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

	$operatorValue=$address;
}break;

no problems until i try to create the socket through the socket_create function
the error is:
Fatal error: Call to undefined function: socket_create() in c:\programmi\ezpublish\ezpublish\lib\eztemplate\classes\eztemplatestringoperator.php on line 192
Fatal error: eZ publish did not finish it's request

should i import (how??) this function in such a way?
is it possible to have a similar behavior?

best regards
alessandro

Bruce Morrison

Sunday 18 April 2004 7:40:39 pm

From the error message it seems that the function "socket_create" is not defined. What version of php are you using? This function was inroduced in 4.1 (see http://au.php.net/manual/en/function.socket-create.php)

Is line 192 the line with the socket_create code ?

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Alessandro Cipriani

Monday 19 April 2004 12:44:24 am

hi bruce!
thanx for your reply, i hope you can help me
yes, the call to the function is in line 192: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

i'm using ezpublish 3.3-1 with php 4.3.4
what can be the problem? should i import this function in my eztemplatestringoperator.php file?

cheers
alessandro

Bruce Morrison

Monday 19 April 2004 4:06:54 pm

Hi Alessandro

According to http://au.php.net/manual/en/ref.sockets.php -" The socket functions described here are part of an extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure."

I don't believe that this issue is php related.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Alessandro Cipriani

Tuesday 20 April 2004 12:05:03 am

thanks bruce
there's no way to enable this extension at compile time?
i don't know php (i'm starting learning it now) but i need this feature.
also i think that such a feature will be useful to extend ezpublish, to make it comunicate with other applications.

is there some built-in way to comunicate with other applications by sending them some informations?
Could be ezSoap useful to me?

cheers
alessandro

Alessandro Cipriani

Tuesday 20 April 2004 2:31:31 am

bruce,
is it possible to compile php under windows?
my server is on a windows 2k machine

cheers
alessandro

Bruce Morrison

Tuesday 20 April 2004 2:46:48 am

Don't worry about compiling php under windows - use one of these apache/php/mysql packages :
http://www.firepages.com.au/
http://sourceforge.net/projects/phptriad
http://www.foxserv.net/portal.php

or the many more found at http://www.google.com.au/search?hl=en&ie=UTF-8&oe=UTF-8&q=mysql+php+apache++windows&btnG=Search&meta=

I use linux and cannot vouch for any of them with ezPublish. I have used the first 2 listed in the very distant past.

Cheers
Bruce http://www.designit.com.au

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Alessandro Cipriani

Tuesday 20 April 2004 3:19:15 am

hi bruce
thanx for your support
i didn't need to compile anything!!!
i simply "decommented" the line
extension=php_sockets.dll
in my php.ini file
and downloaded the php_sockets.dll (http://kromann.info/php4/php_sockets.dll) and placed it into the winnt/system32 directory

all works perfectly!!

best regards
alessandro