Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

XML-RPC how to make it work?

Anshe Chung
Business Girl
Join date: 22 Mar 2004
Posts: 1,615
12-06-2004 09:00
Hi :-)

We want to collect data in mySQL database. It is on one web server that can run PHP 4.0 script.

Question: how do we get data from in world prim into database table? And how do we get data back from database table in world?

Mmmm, maybe can somebody explain or point to one thread with examples that could help us understand how to do?
_____________________
ANSHECHUNG.COM: Buy land - Sell land - Rent land - Sell sim - Rent store - Earn L$ - Buy L$ - Sell L$

SLEXCHANGE.COM: Come join us on Second Life's most popular website for shopping addicts. Click, buy and smile :-)
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-06-2004 20:31
You need the PHP RPC-XML Library modules, and then #include them into your php scripts to call the various functions it supports.

I'm assuming you are not running IIS from your computer... or rather you are using someone elses computer for hosting. In which case, if you want the the mySQL database to be updated automatically with your php scripts, you could use the email server's filtering options, so when you email your data from SL to an email address you create -- it would filter the email and autorespond it to your script, then your script could put it into your database.

something like this:

Object in SL --> Emails [email]yourname@yourdomain.com[/email] --> Autoresponder --> yourdomain.com/yourscript.php --> script parses data --> mySQL --> SELECT * FROM YourdatabaseName * WHERE information etc.

using RPC-XML it would be:
Open Script in browser --> Script queries SL with RPC Channel --> Object Responds to Query --> Update mySQL --> Refresh page

using both:
Object in SL --> Emails [email]yourname@yourdomain.com[/email] with it's RPC Channel --> Autoresponder --> yourdomain.com/yourscript.php --> script takes the RPC Channel, queries SL, receives other information, parses data --> mySQUL etc

#3 is nice because then you don't have to keep hardcoding your RPC Channel (or using htm calls like myscript.php?rpcChannel=0000-0000-0000-0000 through a input box)

Otherwise, if you use rpc-xml with php... you kinda have to keep your web-browser open and set the META info to auto-refresh it to send a query into sl to your object and is kindof a pita. So emailing would be a better route for that.

ALTHOUGH, don't super-quote me on this... i haven't 'completely' explored every option with PHP to do this other then with emailing a script... I've explored the library functions a lot and it seems to be a bit useless without a webpage open constantly. Perhaps someone else might have a better way. At any route, let me know if you need the rpc-xml library stuff.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
12-07-2004 01:49
One thing, I get the feeling youre adding a script to each prim in a build in order to record the build? I could be wrong, but its just the impression I get?

That would be a *lot* of emails -> probably enough to trigger alarms around the Linden sysop area.

What you might consider doing is having a proxy object within SL collect the data from the prims, and chunk it into emails, packing the data quite tightly, before forwarding this onto your out-world server. (And vise versa on inbound).

Azelda
_____________________
Maxx Monde
Registered User
Join date: 14 Nov 2003
Posts: 1,848
12-07-2004 04:49
Theoretical: If Lord Vader appeared to you two and asked how to make the Death Star more effective, would you...

A) Offer detailed help.

B) Offer detailed help, and a consultation fee.

C) Decline to help, considering the possible use of such knowledge.

D) Run screaming, because Vader can choke you with his *mind*.

Just curious.
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
12-07-2004 05:14
Well, how much does Darth Vader pay?
_____________________
Kris Ritter
paradoxical embolism
Join date: 31 Oct 2003
Posts: 6,627
12-07-2004 05:17
Philosophical: Re: Destroying the DeathStar

Is Luke Skywalker a hero or a mass murderer?






What? I thought we were playing a game?
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
12-07-2004 05:18
From: Azelda Garcia
Well, how much does Darth Vader pay?


A 'get out of force-grip free' card?
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
12-07-2004 05:19
From: Kris Ritter
Philosophical: Re: Destroying the DeathStar

Is Luke Skywalker a hero or a mass murderer?






What? I thought we were playing a game?


Quite clearly he was liberating the people of the deathstar and giving them freedom.
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Kris Ritter
paradoxical embolism
Join date: 31 Oct 2003
Posts: 6,627
12-07-2004 05:27
From: Adam Zaius
Quite clearly he was liberating the people of the deathstar and giving them freedom.


Liberating/Freedom = Being blown the fuck up? :eek:

Oh wait! So it does. After all, we're liberating the Iraqi's!
_____________________
CrystalShard Foo
1+1=10
Join date: 6 Feb 2004
Posts: 682
12-07-2004 05:41
E. Give information that will actually make the Deathstar dance the Hokey Pokey rather then make it more efficent.

Or you could just recommend him to try the latest revision of Longhorn - that should enable the same effect.
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-07-2004 08:51
From: Azelda Garcia
One thing, I get the feeling youre adding a script to each prim in a build in order to record the build? I could be wrong, but its just the impression I get?

That would be a *lot* of emails -> probably enough to trigger alarms around the Linden sysop area.

What you might consider doing is having a proxy object within SL collect the data from the prims, and chunk it into emails, packing the data quite tightly, before forwarding this onto your out-world server. (And vise versa on inbound).

Azelda


Good call Az, i forget to add some things i take for granted as standard practice.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Alicia Eldritch
the greatest newbie ever.
Join date: 13 Nov 2004
Posts: 267
12-07-2004 09:02
From: Maxx Monde
Theoretical: If Lord Vader appeared to you two and asked how to make the Death Star more effective, would you...

A) Offer detailed help.

B) Offer detailed help, and a consultation fee.

C) Decline to help, considering the possible use of such knowledge.

D) Run screaming, because Vader can choke you with his *mind*.

Just curious.



LOL.
Alicia Eldritch
the greatest newbie ever.
Join date: 13 Nov 2004
Posts: 267
12-07-2004 09:09
From: Water Rogers

using both:
Object in SL --> Emails [email]yourname@yourdomain.com[/email] with it's RPC Channel --> Autoresponder --> yourdomain.com/yourscript.php --> script takes the RPC Channel, queries SL, receives other information, parses data --> mySQUL etc

#3 is nice because then you don't have to keep hardcoding your RPC Channel (or using htm calls like myscript.php?rpcChannel=0000-0000-0000-0000 through a input box)

Otherwise, if you use rpc-xml with php... you kinda have to keep your web-browser open and set the META info to auto-refresh it to send a query into sl to your object and is kindof a pita. So emailing would be a better route for that.


This is basically the way to do it. Keep in mind, you can use XML-RPC to poke the webserver, activating the php script behind the scenes. No page needs to be open.

Also, this is important:
From: Azelda Garcia

What you might consider doing is having a proxy object within SL collect the data from the prims, and chunk it into emails, packing the data quite tightly, before forwarding this onto your out-world server. (And vise versa on inbound).


So... umm... what they said, with my two cents. o.0
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-07-2004 12:17
so here's your xmlrpc.inc script:
CODE
<?
//Note: this code requires version 4.10 or higher of PHP.

function & XML_serialize(&$data, $level = 0, $prior_key = NULL){
#assumes a hash, keys are the variable names
$xml_serialized_string = "";
while(list($key, $value) = each($data)){
$inline = false;
$numeric_array = false;
$attributes = "";
#echo "My current key is '$key', called with prior key '$prior_key'<br>";
if(!strstr($key, " attr")){ #if it's not an attribute
if(array_key_exists("$key attr", $data)){
while(list($attr_name, $attr_value) = each($data["$key attr"])){
#echo "Found attribute $attribute_name with value $attribute_value<br>";
$attr_value = &htmlspecialchars($attr_value, ENT_QUOTES);
$attributes .= " $attr_name=\"$attr_value\"";
}
}

if(is_numeric($key)){
#echo "My current key ($key) is numeric. My parent key is '$prior_key'<br>";
$key = $prior_key;
}else{
#you can't have numeric keys at two levels in a row, so this is ok
#echo "Checking to see if a numeric key exists in data.";
if(is_array($value) and array_key_exists(0, $value)){
# echo " It does! Calling myself as a result of a numeric array.<br>";
$numeric_array = true;
$xml_serialized_string .= XML_serialize($value, $level, $key);
}
#echo "<br>";
}

if(!$numeric_array){
$xml_serialized_string .= str_repeat("\t", $level) . "<$key$attributes>";

if(is_array($value)){
$xml_serialized_string .= "\r\n" . XML_serialize($value, $level+1);
}else{
$inline = true;
$xml_serialized_string .= $value;
}

$xml_serialized_string .= (!$inline ? str_repeat("\t", $level) : "") . "</$key>\r\n";
}
}else{
#echo "Skipping attribute record for key $key<bR>";
}
}
if($level == 0){
$xml_serialized_string = "<?xml version=\"1.0\" ?>\r\n" . $xml_serialized_string;
return $xml_serialized_string;
}else{
return $xml_serialized_string;
}
}

function & XML_unserialize(&$xml){
$values = array();
$indexes = array();
$xml_parser = xml_parser_create();
xml_parser_set_option ($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($xml_parser, $xml, &$values, &$indexes);
xml_parser_free($xml_parser);

$root = array();
$current_parent = &$root;
$value_count = count($values);
for($n = 0; $n<$value_count; $n++){
$value = $values[$n];
$level = $value['level'];
$type = $value['type'];
$tag = $value['tag'];
$val = $value['value'];
$attributes = $value['attributes'];

$attribute_string = '';
if(($type == 'open' or $type == 'complete')){
#echo "At $type tag $tag, level $level. <b>Value is '$val'</b><br>\n";
if(array_key_exists($tag, $current_parent)){
#echo "There's already an instance of '$tag' at the current level ($level)<br>\n";
if(is_array($current_parent[$tag]) and array_key_exists(0, $current_parent[$tag])){ #if the keys are numeric
#need to make sure they're numeric (account for attributes)
$key = count_numeric_items($current_parent[$tag]);
#echo "There are $key instances: the keys are numeric.<br>\n";
}else{
#echo "There is only one instance. Shifting everything around<br>\n";
$temp = &$current_parent[$tag];
unset($current_parent[$tag]);
$current_parent[$tag][0] = &$temp;
if(array_key_exists("$tag attr", $current_parent)){
$temp = &$current_parent["$tag attr"];
unset($current_parent["$tag attr"]);
$current_parent[$tag]["0 attr"] = &$temp;
}
$key = 1;
}
$current_parent = &$current_parent[$tag];
}else{
$key = $tag;
}
if($attributes){
$current_parent["$key attr"] = $attributes;
}
}
if($type == 'open'){
$current_parent[$key] = array();
$current_parent = &$current_parent[$key];
if(!is_numeric($key)){
$current_level_parent[$level-1] = &$current_parent;
}
}elseif($type == 'complete'){
#echo "Parsing: key is $key and val is " . show($val, var_dump, true) . "<br>\n";
$current_parent[$key] = $val;
if(is_numeric($key)){
$current_parent = &$current_level_parent[$level-2];
}
}elseif($type == 'close'){
if($level > 1){
$current_parent = &$current_level_parent[$level-2];
}else{
$current_parent = &$root;
}
}
}
return $root;
}

function & XMLRPC_prepare($data, $type = NULL){
if(is_array($data)){
$num_elements = count($data);
if((array_key_exists(0, $data) or !$num_elements) and $type != 'struct'){ #it's an array
if(!$num_elements){ #if the array is empty
$returnvalue = array('array' => array('data' => NULL));
}else{
$returnvalue['array']['data']['value'] = array();
$temp = &$returnvalue['array']['data']['value'];
$count = count_numeric_items($data);
for($n=0; $n<$count; $n++){
$type = NULL;
if(array_key_exists("$n type", $data)){
$type = $data["$n type"];
}
$temp[$n] = XMLRPC_prepare(&$data[$n], $type);
}
}
}else{ #it's a struct
if(!$num_elements){ #if the struct is empty
$returnvalue = array('struct' => NULL);
}else{
$returnvalue['struct']['member'] = array();
$temp = &$returnvalue['struct']['member'];
while(list($key, $value) = each($data)){
if(substr($key, -5) != ' type'){ #if it's not a type specifier
$type = NULL;
if(array_key_exists("$key type", $data)){
$type = $data["$key type"];
}
$temp[] = array('name' => $key, 'value' => XMLRPC_prepare(&$value, $type));
}
}
}
}
}else{ #it's a scalar
if(!$type){
if(is_int($data)){
$returnvalue['int'] = $data;
return $returnvalue;
}elseif(is_float($data)){
$returnvalue['double'] = $data;
return $returnvalue;
}elseif(is_bool($data)){
$returnvalue['boolean'] = $data;
return $returnvalue;
}elseif(preg_match('/\d{8}T\d{2}:\d{2}:\d{2}/', $data, $matches)){ #it's a date
$returnvalue['dateTime.iso8601'] = $data;
return $returnvalue;
}elseif(is_string($data)){
$returnvalue['string'] = htmlspecialchars($data);
return $returnvalue;
}
}else{
$returnvalue[$type] = $data;
}
}
return $returnvalue;
}

function & XMLRPC_adjustValue(&$current_node){
if(is_array($current_node)){
if(isset($current_node['array'])){
if(!is_array($current_node['array']['data'])){
#If there are no elements, return an empty array
return array();
}else{
#echo "Getting rid of array -> data -> value<br>\n";
$temp = &$current_node['array']['data']['value'];
if(is_array($temp) and array_key_exists(0, $temp)){
$count = count($temp);
for($n=0;$n<$count;$n++){
$temp2[$n] = &XMLRPC_adjustValue(&$temp[$n]);
}
$temp = &$temp2;
}else{
$temp2 = &XMLRPC_adjustValue(&$temp);
$temp = array(&$temp2);
#I do the temp assignment because it avoids copying,
# since I can put a reference in the array
#PHP's reference model is a bit silly, and I can't just say:
# $temp = array(&XMLRPC_adjustValue(&$temp));
}
}
}elseif(isset($current_node['struct'])){
if(!is_array($current_node['struct'])){
#If there are no members, return an empty array
return array();
}else{
#echo "Getting rid of struct -> member<br>\n";
$temp = &$current_node['struct']['member'];
if(is_array($temp) and array_key_exists(0, $temp)){
$count = count($temp);
for($n=0;$n<$count;$n++){
#echo "Passing name {$temp[$n][name]}. Value is: " . show($temp[$n][value], var_dump, true) . "<br>\n";
$temp2[$temp[$n]['name']] = &XMLRPC_adjustValue(&$temp[$n]['value']);
#echo "adjustValue(): After assigning, the value is " . show($temp2[$temp[$n]['name']], var_dump, true) . "<br>\n";
}
}else{
#echo "Passing name $temp[name]<br>\n";
$temp2[$temp['name']] = &XMLRPC_adjustValue(&$temp['value']);
}
$temp = &$temp2;
}
}else{
$types = array('string', 'int', 'i4', 'double', 'dateTime.iso8601', 'base64', 'boolean');
$fell_through = true;
foreach($types as $type){
if(array_key_exists($type, $current_node)){
#echo "Getting rid of '$type'<br>\n";
$temp = &$current_node[$type];
#echo "adjustValue(): The current node is set with a type of $type<br>\n";
$fell_through = false;
break;
}
}
if($fell_through){
$type = 'string';
#echo "Fell through! Type is $type<br>\n";
}
switch ($type){
case 'int': case 'i4': $temp = (int)$temp; break;
case 'string': $temp = (string)$temp; break;
case 'double': $temp = (double)$temp; break;
case 'boolean': $temp = (bool)$temp; break;
}
}
}else{
$temp = (string)$current_node;
}
return $temp;
}

function XMLRPC_getParams($request){
if(!is_array($request['methodCall']['params'])){
#If there are no parameters, return an empty array
return array();
}else{
#echo "Getting rid of methodCall -> params -> param<br>\n";
$temp = &$request['methodCall']['params']['param'];
if(is_array($temp) and array_key_exists(0, $temp)){
$count = count($temp);
for($n = 0; $n < $count; $n++){
#echo "Serializing parameter $n<br>";
$temp2[$n] = &XMLRPC_adjustValue(&$temp[$n]['value']);
}
}else{
$temp2[0] = &XMLRPC_adjustValue($temp['value']);
}
$temp = &$temp2;
return $temp;
}

}

function XMLRPC_getMethodName($methodCall){
#returns the method name
return $methodCall['methodCall']['methodName'];
}

function XMLRPC_request($site, $location, $methodName, $params = NULL, $user_agent = NULL){
list($site, $port) = explode(':', $site);
if(!is_numeric($port)){
$port = 80;
}
$data["methodCall"]["methodName"] = $methodName;
$param_count = count($params);
if(!$param_count){
$data["methodCall"]["params"] = NULL;
}else{
for($n = 0; $n<$param_count; $n++){
$data["methodCall"]["params"]["param"][$n]["value"] = $params[$n];
}
}
$data = XML_serialize($data);

XMLRPC_debug('XMLRPC_request', "<p>Received the following parameter list to send:</p>" . XMLRPC_show($params, print_r, true));
$conn = fsockopen ($site, $port); #open the connection
if(!$conn){ #if the connection was not opened successfully
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_request', "<p>Connection failed: Couldn't make the connection to $site.</p>");
}
return array(false, array('faultCode'=>10532, 'faultString'=>"Connection failed: Couldn't make the connection to $site."));
}else{
$headers =
"POST $location HTTP/1.0\r\n" .
"Host: $site\r\n" .
"Connection: close\r\n" .
($user_agent ? "User-Agent: $user_agent\r\n" : '') .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($data) . "\r\n\r\n";

fputs($conn, "$headers");
fputs($conn, $data);

if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_request', "<p>Sent the following request:</p>\n\n" . XMLRPC_show($headers . $data, print_r, true));
}

#socket_set_blocking ($conn, false);
$response = "";
while(!feof($conn)){
$response .= fgets($conn, 1024);
}
fclose($conn);
#strip headers off of response

$data = XML_unserialize(substr($response, strpos($response, "\r\n\r\n")+4));

if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_request', "<p>Received the following response:</p>\n\n" . XMLRPC_show($response, print_r, true) . "<p>Which was serialized into the following data:</p>\n\n" . XMLRPC_show($data, print_r, true));
}
if(isset($data['methodResponse']['fault'])){
$return = array(false, XMLRPC_adjustValue(&$data['methodResponse']['fault']['value']));
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_request', "<p>Returning:</p>\n\n" . XMLRPC_show($return, var_dump, true));
}
return $return;
}else{
$return = array(true, XMLRPC_adjustValue(&$data['methodResponse']['params']['param']['value']));
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_request', "<p>Returning:</p>\n\n" . XMLRPC_show($return, var_dump, true));
}
return $return;
}
}
}

function XMLRPC_response($return_value, $server = NULL){
$data["methodResponse"]["params"]["param"]["value"] = &$return_value;
$return = XML_serialize(&$data);

if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_response', "<p>Received the following data to return:</p>\n\n" . XMLRPC_show($return_value, print_r, true));
}

header("Connection: close");
header("Content-Length: " . strlen($return));
header("Content-Type: text/xml");
header("Date: " . date("r"));
if($server){
header("Server: $server");
}

if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_response', "<p>Sent the following response:</p>\n\n" . XMLRPC_show($return, print_r, true));
}
echo $return;
}

function XMLRPC_error($faultCode, $faultString, $server = NULL){
$array["methodResponse"]["fault"]["value"]["struct"]["member"] = array();
$this = &$array["methodResponse"]["fault"]["value"]["struct"]["member"];
$this[0]["name"] = "faultCode";
$this[0]["value"]["int"] = $faultCode;
$this[1]["name"] = "faultString";
$this[1]["value"]["string"] = $faultString;

$return = XML_serialize($array);

header("Connection: close");
header("Content-Length: " . strlen($return));
header("Content-Type: text/xml");
header("Date: " . date("r"));
if($server){
header("Server: $server");
}
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_error', "<p>Sent the following error response:</p>\n\n" . XMLRPC_show($return, print_r, true));
}
echo $return;
}

function XMLRPC_convert_timestamp_to_iso8601($timestamp){
#takes a unix timestamp and converts it to iso8601 required by XMLRPC
#an example iso8601 datetime is "20010822T03:14:33"
return date("Ymd\TH:i:s", $timestamp);
}

function XMLRPC_convert_iso8601_to_timestamp($iso8601){
return strtotime($iso8601);
}

function XMLRPC_parse(&$request){
return XML_unserialize(&$request);
}

function count_numeric_items(&$array){
return is_array($array) ? count(array_filter(array_keys($array), is_numeric)) : 0;
}

function XMLRPC_debug($function_name, $debug_message){
$GLOBALS['XMLRPC_DEBUG_INFO'][] = array($function_name, $debug_message);
}

function XMLRPC_debug_print(){
if($GLOBALS['XMLRPC_DEBUG_INFO']){
echo "<table border=\"1\" width=\"100%\">\n";
foreach($GLOBALS['XMLRPC_DEBUG_INFO'] as $debug){
echo "<tr><th style=\"vertical-align: top\">$debug[0]</th><td>$debug[1]</td></tr>\n";
}
echo "</table>\n";
unset($GLOBALS['XMLRPC_DEBUG_INFO']);
}else{
echo "<p>No debugging information available yet.</p>";
}
}

function XMLRPC_show($data, $func = "print_r", $return_str = false){
ob_start();
$func($data);
$output = ob_get_contents();
ob_end_clean();
if($return_str){
return "<pre>" . htmlspecialchars($output) . "</pre>\n";
}else{
echo "<pre>", htmlspecialchars($output), "</pre>\n";
}
}

?>


...continued on next post....
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-07-2004 12:17
and here's a sample connect script i used to send an object shoutCAST info:
CODE
<?php
include("xmlrpc.inc");

$host = $_REQUEST['ip'];
$port = $_REQUEST['port'];
$obj_key = $_REQUEST['key'];
$rfrshrate = 10;

define("XMLRPC_DEBUG", 1);

$channel = $key;
$intValue = 1;

//Header("Content-type: text/html");

$fp = fsockopen("$host", $port, &$errno, &$errstr, 30);

$txt_connected = "Connected to Object | <a href=\"http://$host:$port/listen.pls\">Listen to Stream</a>";

if(!$fp) {
$song_Title = "Unable to connect to shoutCAST server";
$txt_connected = "Not Connected to Object";
$caption = "ERROR";
$rfrshrate = 9999;
}
else{
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n");
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp);
$page = ereg_replace(".*<body>", "", $page);
$page = ereg_replace("</body>.*", ",", $page);
$numbers = explode(",",$page);
$currentlisteners=$numbers[0];
$connected=$numbers[1];
$peaklisteners=$numbers[2];
$maxlisteners=$numbers[3];
$reportedlisteners=$numbers[4];
$bitrate=$numbers[5];

$strValue = "$numbers[6].$reportedlisteners.$maxlisteners.$peaklisteners.$bitrate";

$array["Channel"] = $channel;
$array["IntValue"] = $intValue;
$array["StringValue"] = $strValue;
list($success2, $response) = XMLRPC_request('xmlrpc.secondlife.com', '/cgi-bin/xmlrpc.cgi', 'llRemoteData', array(XMLRPC_prepare($array)));

if ($success2) {
//print "StringValue: " . $response["StringValue"];
$resp_key = $response["StringValue"];
$song_Title = $numbers[6];
$caption = "TRACK NAME";
} else {
$song_Title= $response['faultString'];
$rfrshrate=9999;
$caption="ERROR";
$txt_connected = "Not Connected to Object";
}
}

//XMLRPC_response($song_Title, $server = NULL);

echo "<html>";
echo "<head>";
echo "<title>SLife SCast Sever [$host:$port]</title>";
echo "<meta http-equiv=\"REFRESH\" CONTENT=\"$rfrshrate\">\n";
echo "</head>";

echo "<body bgcolor=\"#FFFFFF\" text=\"#000000\">";

echo "<table width=\"450\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">";
echo " <tr>";
echo " <td width=\"450\" height=\"98\" valign=\"top\">";
echo " <div align=\"center\">";
echo " <p><font size=\"4\"><b>ShoutCAST Second Life Web Server</b></font></p>";
echo " <p>$host:$port<br>";
echo " $txt_connected</p>";
echo " </div>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"78\" valign=\"top\">";
echo " <table width=\"100%\" border=\"1\" bordercolor=\"black\" cellpadding=\"0\" cellspacing=\"0\">";
echo " <tr>";
echo " <td colspan=\"3\" height=\"17\" valign=\"middle\" bgcolor=\"#000099\">";
echo " <div align=\"center\"><font size=\"2\" color=\"#FFFFFF\">$caption</font></div>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"17\" valign=\"top\" colspan=\"3\">";
echo " <div align=\"center\"><font size=\"3\">$song_Title</font></div>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"17\" width=\"148\" valign=\"top\" bgcolor=\"#CC0000\">";
echo " <div align=\"center\"><font size=\"2\" color=\"#FFFFFF\">Max Listeners</font></div>";
echo " </td>";
echo " <td valign=\"top\" width=\"148\" bgcolor=\"#CC0000\">";
echo " <div align=\"center\"><font size=\"2\" color=\"#FFFFFF\">Current Listeners</font></div>";
echo " </td>";
echo " <td width=\"146\" valign=\"top\" bgcolor=\"#CC0000\">";
echo " <div align=\"center\"><font size=\"2\" color=\"#FFFFFF\">Peak Listeners</font></div>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"21\" valign=\"top\">";
echo " <div align=\"center\"><font size=\"3\">$maxlisteners</font></div>";
echo " </td>";
echo " <td valign=\"top\">";
echo " <div align=\"center\"><font size=\"3\">$reportedlisteners</font></div>";
echo " </td>";
echo " <td valign=\"top\">";
echo " <div align=\"center\"><font size=\"3\">$peaklisteners</font></div>";
echo " </td>";
echo " </tr>";
echo " </table>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"15\"></td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"19\" valign=\"top\">";
echo " <div align=\"center\">Connection Information | <a href=\"http://www.midnightstudios.net/shoutcast/index.htm\">Change</a></div>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"54\" valign=\"top\">";
echo " <table width=\"100%\" border=\"1\" bordercolor=\"Black\" cellpadding=\"0\" cellspacing=\"0\">";
echo " <tr>";
echo " <td width=\"446\" height=\"18\" valign=\"top\"><font size=\"2\">Object Key: ";
echo " <font color=\"#FF0000\">$resp_key</font></font><br>";
echo " <font size=\"2\">Data Channel: <font color=\"#FF0000\">$obj_key</font></font></td>";
echo " </tr>";
echo " <tr>";
echo " <td valign=\"top\" height=\"14\"><font size=\"2\">Host IP: <font color=\"#006600\">$host</font></font></td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"13\" valign=\"top\"><font size=\"2\">Port: <font color=\"#990000\">$port</font></font></td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"13\" valign=\"top\"><font size=\"2\">Bitrate: <font color=\"#990000\">$bitrate kb/s</font></font></td>";
echo " </table>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"9\"></td>";
echo " </tr>";
echo " <tr>";
echo " <td height=\"14\" valign=\"top\" bgcolor=\"#000000\">";
echo " <div align=\"center\"><font color=\"#FFFFFF\"><b>Warning: Closing this page will kill the connection.</b></font></div>";
echo " </td>";
echo " </tr>";
echo "</table>";
echo "</body>";
echo "</html>";
?>


like alicia said, you can have it poke at the server so you don't actually have to have a page open... this example does require a page open however (checks for song changing on the shoutCAST station)

Anyway, so yeah... that's an example of how you can connect and process some info.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Pleze Playfair
Registered User
Join date: 27 Aug 2004
Posts: 100
12-07-2004 14:25
From: Water Rogers
Object in SL --> Emails [email]yourname@yourdomain.com[/email] --> Autoresponder --> yourdomain.com/yourscript.php --> script parses data --> mySQL --> SELECT * FROM YourdatabaseName * WHERE information etc.

using RPC-XML it would be:
Open Script in browser --> Script queries SL with RPC Channel --> Object Responds to Query --> Update mySQL --> Refresh page

using both:
Object in SL --> Emails [email]yourname@yourdomain.com[/email] with it's RPC Channel --> Autoresponder --> yourdomain.com/yourscript.php --> script takes the RPC Channel, queries SL, receives other information, parses data --> mySQUL etc

#3 is nice because then you don't have to keep hardcoding your RPC Channel (or using htm calls like myscript.php?rpcChannel=0000-0000-0000-0000 through a input box)

Otherwise, if you use rpc-xml with php... you kinda have to keep your web-browser open and set the META info to auto-refresh it to send a query into sl to your object and is kindof a pita. So emailing would be a better route for that.

ALTHOUGH, don't super-quote me on this... i haven't 'completely' explored every option with PHP to do this other then with emailing a script... I've explored the library functions a lot and it seems to be a bit useless without a webpage open constantly. Perhaps someone else might have a better way. At any route, let me know if you need the rpc-xml library stuff.

--Water


I thought about these things as well .. wish they'd implement outgoing soon hehe.

You could also setup a CRON job that uses lynx to hit the php page at a specific interval. Some hosting providers allow this and some don't. I thought about doing the refresh html page , but my computer hasn't been too reliable recently , sucks.
Pleze Playfair
Registered User
Join date: 27 Aug 2004
Posts: 100
12-07-2004 14:28
From: Azelda Garcia
One thing, I get the feeling youre adding a script to each prim in a build in order to record the build? I could be wrong, but its just the impression I get?

That would be a *lot* of emails -> probably enough to trigger alarms around the Linden sysop area.

What you might consider doing is having a proxy object within SL collect the data from the prims, and chunk it into emails, packing the data quite tightly, before forwarding this onto your out-world server. (And vise versa on inbound).

Azelda


This is a worry of mine. If you have a ton of SL clients sending email to one email address the website feeds off of it might possibly be considered a spam/flood and blocked.

I wish we could get a definte number on how many emails are considered a flood and how many XML requests are allowed per specific time interval before they become too much .. would be nice.
Pleze Playfair
Registered User
Join date: 27 Aug 2004
Posts: 100
12-07-2004 14:34
From: Azelda Garcia
One thing, I get the feeling youre adding a script to each prim in a build in order to record the build? I could be wrong, but its just the impression I get?

That would be a *lot* of emails -> probably enough to trigger alarms around the Linden sysop area.

What you might consider doing is having a proxy object within SL collect the data from the prims, and chunk it into emails, packing the data quite tightly, before forwarding this onto your out-world server. (And vise versa on inbound).

Azelda


This is a worry of mine. If you have a ton of SL clients sending email to one email address the website feeds off of it might possibly be considered a spam/flood and blocked.

I wish we could get a definte number on how many emails are considered a flood and how many XML requests are allowed per specific time interval before they become too much .. would be nice.
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-07-2004 14:50
From: Pleze Playfair
This is a worry of mine. If you have a ton of SL clients sending email to one email address the website feeds off of it might possibly be considered a spam/flood and blocked.

I wish we could get a definte number on how many emails are considered a flood and how many XML requests are allowed per specific time interval before they become too much .. would be nice.


It would really depend on your email server (or host's server). I've used hotmail and yahoo with sl over the last couple of years to send IM's to my email address when i'm offline, and i've never ever had a problem with it (roughly 200 emails a day)... also, if you paid or have your own hosting site, then more often then not their email servers won't care how much is being pushed through. Although i did have ONE problem once with midnightstudios.net email servers, but it was the company's fault (basically too many emails qeued up on their entire server at once)... was corrected tho.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Araiya Bomazi
A. Bomazi-Tomba. :)
Join date: 3 Dec 2004
Posts: 51
02-27-2005 18:04
From: Pleze Playfair
I thought about these things as well .. wish they'd implement outgoing soon hehe.

You could also setup a CRON job that uses lynx to hit the php page at a specific interval. Some hosting providers allow this and some don't. I thought about doing the refresh html page , but my computer hasn't been too reliable recently , sucks.


I hate reviving the old, but I had a relevant question:

For those who can't set up cron jobs, could they not use procmail to look at emails...
Say,
CODE

:0
* ^To:.*notsofakeemailaddress@adomainidonotshare.tld
* < 8192
{ INCLUDERC=/home/mydir/procrecipes/rc.secondlife }

With a recipe that is designed to process the incoming email in a way that the person would like, and would also trigger a script at the same time?

This, of course, assumes that the person never sends more than 8kb of data at a time, often securing it from much of the cruft floating around, such as the viruses that attach files to emails. :)

Since I've never sent an email from an object in-world, I don't have any emails to better strengthen that recipe up there with, to scrub the possibility of bogus emails being sent, and polluting any data one may receive.