Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

PHP Example XML-RPC Client

Eddy Stryker
libsecondlife Developer
Join date: 6 Jun 2004
Posts: 353
07-02-2004 09:54
This uses the excellent XML-RPC library provided by Keith Devens. I started using the one built in with PHP 4.3.0 and later but this one is really convenient and provides super debugging info, plus you don't have to worry about the functions breaking in a new PHP version. Info here and download here. Rename the "source" file to something like xmlrpc.inc and include("xmlrpc.inc";);

EDIT: You don't have to worry about the functions breaking in a new PHP version, unless the new version breaks the functions, as detailed in Gwnyeth's post below. I guess you can never win.

CODE

<?php

include("xmlrpc.inc");

define("XMLRPC_DEBUG", 1);

$channel = "1c36254b-d1c1-0ac0-9635-4edfb2db218b";
$strValue = "Hello Second World!";
$intValue = 1;

$array["Channel"] = $channel;
$array["IntValue"] = $intValue;
$array["StringValue"] = $strValue;

list($success, $response) = XMLRPC_request('xmlrpc.secondlife.com',
'/cgi-bin/xmlrpc.cgi', 'llRemoteData', array(XMLRPC_prepare($array)));

if ($success) {
print "StringValue: " . $response["StringValue"] . "\n<br>IntValue: " . $response["IntValue"];
} else {
print "<h3>Failure</h3>\n";
print "<strong>faultCode:</strong> " . $response['faultCode'] .
"<br>\n";
print "<strong>faultString:</strong> " . $response['faultString'] .
"<br><br>\n";
}

print "<hr><br>\n\n";

XMLRPC_debug_print();

?>



Note that this uses a hardcoded channel. From my limited testing an lsl script will retain it's channel until you change the script, which from the SL server perspective makes it a new script. So you end up doing a lot of copy-paste between the lsl and your php, but I really don't know of any way to get the channel to the server. I don't own my own server, I don't have the ability to setup an e-mail trap and parse mail messages, not even considering the 20 second delay that imposes plus any additional mail routing delays.
Eddy Stryker
libsecondlife Developer
Join date: 6 Jun 2004
Posts: 353
07-02-2004 10:26
Some additional info about error codes (I will update this as I stumble upon more potential errors), faultCode 1 means the script timed out. This could mean the object isn't rezzed, llOpenDataChannel() never got called, or the script received the call successfully but never returned anything. You should always return at least an integer code to let the client know what happened. faultCode 2 means the specified channel wasn't found. This apparently means a channel that has never been created, because if a channel is created and that script (and/or containing object) is destroyed, the channel is still valid. If you accidentally pass something other than llRemoteData for the function call name you'll get an error code like -32,000 something.
Dan Rhodes
hehe
Join date: 5 Jul 2003
Posts: 268
07-02-2004 12:48
This is awesome, thanks man .. been looking through it :)
Gwyneth Llewelyn
Winking Loudmouth
Join date: 31 Jul 2004
Posts: 1,336
07-24-2006 18:00
Just a slight warning. I've been using Keith Devens most excellent XML-RPC Library for almost two years now (well, since finding this post really!) and it worked flawlessly... until I upgraded from PHP4 to PHP5! Make sure you have allow_call_time_pass_reference = On on your /etc/php.ini file!
_____________________

Mythridian Almodovar
Registered User
Join date: 23 Aug 2007
Posts: 1
10-28-2009 04:04
From: Eddy Stryker

EDIT: You don't have to worry about the functions breaking in a new PHP version, unless the new version breaks the functions, as detailed in Gwnyeth's post below. I guess you can never win.
....
Note that this uses a hardcoded channel. From my limited testing an lsl script will retain it's channel until you change the script, which from the SL server perspective makes it a new script. So you end up doing a lot of copy-paste between the lsl and your php, but I really don't know of any way to get the channel to the server. I don't own my own server, I don't have the ability to setup an e-mail trap and parse mail messages, not even considering the 20 second delay that imposes plus any additional mail routing delays.

There's a way to have that channel code, if you use a post request from SL to a random website, where you can run php script and save a file.
The channel will be sent only on rez, attach, inventory change (perhaps?).. think that's the most used times when the key changes.
using llHTMLRequest, you simply post the key (uuid) to a php script that will write it on a specific file, on webserver. If it's in the same webserver as "hello world", you change $channel_id="..replace..."; with content of that new created file.

Hope it will help you:)
Required: 1 lsl script+1 php that create a file on disk.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-28-2009 05:16
Woohoo! We have a winner!

This one goes in the necro-posting record books.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
10-28-2009 05:39
Impressive! It takes a lot of work to find a thread that's been dead and undisturbed this long. Way to go!!! :D

AND, it was already a necropost when the previous respondent answered in 2006!!!
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at