Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

PHP sockets

Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
01-19-2009 07:41
Where can i get the informaition for this, my group wants to make a simulation of global warming and I heard that we can use this to get information from another place.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-19-2009 16:16
PHP runs on an outside webserver, using a php script your SL script can call the script address, and the php script will return whatever information it's programmed to in amounts up to 2k bytes (SL limitation) using http requests... however general programming of php scripts is a bit beyond the scope of this forum.

if you're looking to code php yourself, it's a different language, with it's own syntax and command structure, meaning it could take a while for you to get up to speed on it, if thats an issue, or you aren't looking to do it yourself, you MIGHT find someone familiar and willing to do it in products wanted
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
01-19-2009 17:30
uhuh....wow. Thanks, i'll keep this in mind. Where would i go if i want to learn it.
Lyla Tunwarm
Registered User
Join date: 10 Jul 2008
Posts: 179
01-19-2009 18:20
Learn PHP? Global warming will have corrected itself by the time you learn it. However google.com is your friend. http://www.learnphp.org
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-19-2009 20:37
Eh. It's not that difficult to learn. Not really any worse than other C/Java/Javascript like languages. The manual at http://www.php.net/docs.php itself isn't too bad to learn from, especially if you have some programming background already.

Keep in mind, though, that you aren't limited to PHP. Any language that you can use for CGI functionality will do. You can use PHP, Perl, native CGI programs, Java servlets, etc. PHP is a pretty simple and quick one to throw stuff together with, and has a decent library for network/HTTP operations, but has even more drawbacks in terms of typing and declarations (or lack thereof) than Perl IMO.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 07:30
What you want to do is to create a php on your webserver, and then use HTTPRequest function in your LSL script to make an HTTP Request to it. Then you can recieve information php echoed through httpresponse callback.

I have done this quite a bit in my projects, and it works well. You don't need to worry about sockets, just learn how to make HTTPRequests from LSL.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-20-2009 07:32
From: Zeta Eizenstark
uhuh....wow. Thanks, i'll keep this in mind. Where would i go if i want to learn it.


http://letmegooglethatforyou.com/?q=php

on serious note, php.net is a great resource. also first result in google :D
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
01-21-2009 12:21
Entheogen would it be to much to ask if you could send me a sample script of the things that you have done, I learn so much faster that way. Thanks evr1 for all the links on the subject, I appreciate it.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-21-2009 13:29
From: Zeta Eizenstark
Entheogen would it be to much to ask if you could send me a sample script of the things that you have done, I learn so much faster that way. Thanks evr1 for all the links on the subject, I appreciate it.


it can get pretty involved on php side. I use MySQL + PHP on my own webserver, and make HTTPRequests to it to retrieve specific info.

here is something basic. Say you want to retrieve a string from your website. your php script might look something like this:
CODE

<?php

$string_val = "some_value";

echo $string_val;

?>


then in lsl script you do something like this:
CODE

llHTTPRequest( "URL to your php script, [], "" );
....
//then somewhere a handler for the response you will get from the php script
http_response (key request_id, integer status, list metadata, string body)
{
llSay( 0, body ); // this should say "some_value" in general chat channel
}
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
01-21-2009 14:13
I think the line

"then in php script you do something like this:"

might should say


"then in LSL script you do something like this:"
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-21-2009 14:21
From: SuezanneC Baskerville
I think the line

"then in php script you do something like this:"

might should say


"then in LSL script you do something like this:"


Oh yea, whoops, good catch.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
01-21-2009 14:28
so the first bit of code goes in the php side?
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
01-21-2009 15:20
From: Zeta Eizenstark
so the first bit of code goes in the php side?


it's just a simple example, but yea. You can just echo stuff in php (usually you echo html because php is usually used for webpages), and that gets sent back to http_response event handler.

What are you trying to do exactly? If you would like to have a database that you can access inside second life, then php/mysql is a reasonable solution, and you should just learn basic of php/ mysql
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-11-2009 09:23
would SL be able to send input into the php code? Say, i send 1 with LSL it goes to php code which is x + 1 = y, x=whatever i send it with LSL, then it sends back y. Very simple and obviously can be done with LSL alone but i want to use programs outside SL that are a little more complicated than i can make with LSL.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
02-11-2009 09:26
From: Zeta Eizenstark
would SL be able to send input into the php code? Say, i send 1 with LSL it goes to php code which is x + 1 = y, x=whatever i send it with LSL, then it sends back y. Very simple and obviously can be done with LSL alone but i want to use programs outside SL that are a little more complicated than i can make with LSL.


You should really study how php works and how HTTPRequest works in general.

Convention for passing variables is doing something like this <url>?x=5&y=3 would pass x and y to the webserver using GET request. If you want to pass them using POST then just make body of POST request be x=5&y=3.

In PHP use $_GET or $_POST associative arrays to get values of those variables. For example

$x = isset( $_POST["x"] ) ? $_POST["x"] : $_GET["x"];

this line would check if x is in $_POST and if not get it from $_GET. you can also check if it is in $_GET to see if it was passed at all to your script.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-11-2009 12:00
In the reply, on the other hand, you only get the body; no parameters. In some ways that is almost unfortunate, but you can always choose to make it easy on yourself by formatting your reply with say lines like:

x=15
y=32
myBigStringVar=Hello%20little%20iffy%20daddy%20dofus%20man%0Awho%20sits%20on%20the%20stairs%0Aand%20throws%20peanuts%20to%20the%20pigeons%2E

That should make it pretty easy to parse the result.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-11-2009 12:47
O.o I'm sorry if i'm soundidn really nooby but...is that a yes? I really have to start looking into more php code........ :(

Into what other programs does LSL have access too other than php?
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
02-11-2009 13:31
From: Zeta Eizenstark
O.o I'm sorry if i'm soundidn really nooby but...is that a yes? I really have to start looking into more php code........ :(

Into what other programs does LSL have access too other than php?


Anything else that you can make Http Request to? You have to realize, LSL does not have access to php perse. its jsut that LSL makes Http Request to webserver containing php file and webserver executes it per request and returns output to LSL.
Entheogen Aeon
boing boom tschak
Join date: 25 Dec 2007
Posts: 34
02-11-2009 13:33
From: Hewee Zetkin
In the reply, on the other hand, you only get the body; no parameters. In some ways that is almost unfortunate, but you can always choose to make it easy on yourself by formatting your reply with say lines like:

x=15
y=32
myBigStringVar=Hello%20little%20iffy%20daddy%20dofus%20man%0Awho%20sits%20on%20the%20stairs%0Aand%20throws%20peanuts%20to%20the%20pigeons%2E

That should make it pretty easy to parse the result.


that and delimiting items with commas. then you can use http://rpgstats.com/wiki/index.php?title=LlCSV2List
Lily Cicerone
Registered User
Join date: 25 Jan 2007
Posts: 30
02-11-2009 14:03
llHTTPRequest doesn't access PHP exclusively. Rather, what it does is return all code in the body of any web page you could visit through a browser, although it ignores formatting lines and returns them as text, so <h1>This is a header</h1>, which would show up on a web page as header text, would literally be sent to the LSL script as <h1>This is a header</h1>. For dynamic content, you need to use any server side scripting language, most likely for your purposes, either to analyze the content of other pages, or to access data from a mySQL or MSSQL database.

PHP itself is not difficult at all to learn if you already know LSL -- they're both pretty shoddy as scripting languages go, but they use similar syntax, except that PHP doesn't even require that you declare variable types, so math operations can be performed on strings, etc. Learning to use a database can be a bit more complicated.

If you're serious about the project and you find that you can't do it on your own, I am experienced in this, and am available for hire. Contact me in world at any time. If I'm busy, it may take me a few days to get to it, although I try to prioritize commissioned work.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-11-2009 19:43
You're definitely not constrained to PHP. I usually work in Perl. You could do native CGI applications, Java, J2EE, .NET, or whatever. Anything that can respond to an HTTP query.

You can even use static content for some things. It can be useful, for example, if you need to keep track of the key of an in-world server whose key you expect to change very infrequently. Once you start experiencing problems, or if something happens that you KNOW will cause the key to change (like the server being returned to you), you can upload a new key.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-16-2009 12:18
ok, because from what i've been told the geology dep. is working on the sim. in c code. I believe the problem that is presented right now is that they aren't using a website but a different application. I'm trying to find what this application is to see what the best way to reach it.

Either way, whats the best place that i can try to build php code and mess with it in LSL i.e. send it input and take output.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-16-2009 12:50
From: Zeta Eizenstark
Either way, whats the best place that i can try to build php code and mess with it in LSL i.e. send it input and take output.


Hmm. Well, if you're just looking to muck around and test things, you could install a web server on your home computer. Apache is a good one. You'll just have to make sure you can open up a port for it in any hardware and software firewalls you have (and a decent firewall WOULD be a very good idea). This probably won't work if you are behind a corporate or school firewall that you have no administrative access to, though you could contact your network administrator and ask about possibilities.

Otherwise, there are good inexpensive web hosting services out there that will allow you to do PHP and almost always Perl scripting. Free services almost never provide such capabilities though. You might need a domain name to go with it. Certainly if you want to setup some persistent web services, whether from home or a hosting service, you'll want a domain name before long.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-18-2009 12:45
Ok, I originally downloaded just apache to get started but couldn't get it to work. I now have WAMP and it looks a little friendlier to the eye and I made php code (hello world) :) but how do I acces the code through SL?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-18-2009 20:42
You'll have to use your IP address unless you have a domain name that's setup to point to it. To see your real outside IP address (because a router or your ISP sometimes assign you internal ones that only you can use), visit a site like http://www.myipaddress.com.

Note that occasionally your IP address might change if your ISP assigns you a dynamically allocated one (most do nowadays). That's why I recommended a home PC installation for just testing and mucking around. There are ways you can make it work more permanently, but they tend to involve some expense. For example, you could check with your ISP about obtaining a static IP address, and/or buy a domain name. If you buy a domain name but still have a dynamic IP address at home you might need to use a service like that offered by http://www.dyndns.com/.
1 2 3