Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

PHP sockets

Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
02-18-2009 21:32
You'll also have to check the port settings. Most ISPs block some ports, specifically port 80 on home accounts, (that's what the business account upgrades often include). So if you plan to use your home machine, either set up something on a different unused port (8080 perhaps) or make sure your ISP isn't blocking incoming port 80 requests.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-19-2009 09:24
how would the httprequest look like using WAMP?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-19-2009 16:28
it's worth mentioning that one of the main reasons ISP's block access to certain ports ( like 80, the standard http port) is because you aren't allowed to run a web server (or mail server or etc) per your user agreement with them. if caught they can up-charge you, or even cut your service.

you can however run a server on your local network, and create friendly names to use for it via the 'hosts' file (plenty of net examples).

if you can/are running a server on a dynamic IP, it isn't absolutely necessary to get a static IP, or even your own domain name, as there are service that will allow you to use a subdomain (sub.domain.com) with a changing IP (FreeDNS AKA afraid.org is one).

also, in addition to a good firewall, it's suggested that you apply all current patches for the server, and it's related add-ins (like PHP and SQL), as well as reading the documentation about securing them from attacks and misuse.
From: Zeta Eizenstark
how would the httprequest look like using WAMP?

the same as it'd look for any web server, i'd assume the WAMP package you have is set up the standard way, address/filename and maybe search string, with .php meaning the requested file gets handled by the php component.

ex.>
http://forums.secondlife.com/editpost.php?do=editpost&p=2330479
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-20-2009 00:08
That's odd. I haven't heard of many ISPs who don't want you to run a web server, though many don't want you running a COMMERCIAL service (including web servers). Maybe my friends, associates, and I have all just been lucky though. My current ISP not only doesn't care much what I do with my bandwidth, but gives me a small but kick-ass bit of hosted space on their own servers (where I can setup some CGI applications and even have shell access). And that's in their most basic package.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-20-2009 08:16
Wow, I will definitely look up the ISP thing, don't want to get in trouble. So my http request would look somthing like this:
llhttprequest("http://localhost/hi2.php", somelist, "";);

Would I be able to get things from the list to set variables as them. So say I send 1 in the list, would I be able to set x in the php script to 1 from the list I send. Also, I'm confused about the string body part of the request, whats that for.

I've tried using the example that is given in http://wiki.secondlife.com/wiki/LlHTTPRequest[url]writing the scripts exactly on both sides with my url above and it gives me some error msg. This are the scripts I have

[code]
key http_request_id;

default
{
state_entry()
{
http_request_id = llHTTPRequest("http://000.00.000.000/hi.php", [], "");
}

http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == http_request_id)
{
llSay(0, "Here are the results: " + body);
}
}
}
[code]

[php]
<?php header("content-type: text/plain; charset=utf-8"); ?>
Headers received:
<?php

/**
* @author Wouter Hobble
* @copyright 2008
*/

foreach ($_SERVER as $k => $v)
{
if( substr($k, 0, 5) == 'HTTP_')
{
print "\n". $k. "\t". $v;
}
}
?>
[php]

is there anything else I need to change?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-20-2009 11:42
In the URL, change "localhost" to your IP address (or domain and host name). Remember that the script is executing from one of Linden Lab's servers (the one where the simulator for your region happens to be running), not from your computer. So the HTTP request will actually be coming from Somewhere Out There on the Internet.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-21-2009 20:27
I know both cox and comcast had that particular clause at one point (couldn't tell you now, it was only on the paper form) but with heavy p2p usage it seems almost a pointless distinction (both noted would warn you first...usually) heard a few scary instances back when I lurked at dslreports. my current ISP thankfully has no such restrictions
_____________________
|
| . "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
02-23-2009 12:07
so the http request should look like this:
httprequest("http://000.00.000.000/hi2.php",[],"";);
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-23-2009 12:22
From: Zeta Eizenstark
so the http request should look like this:
httprequest("http://000.00.000.000/hi2.php",[],"";);


Yeah, basically. If you run your web server on a port other than 80 (the default for HTTP), you'll also need ":<port>" after the IP address. So if your IP address is 101.23.4.56 and you run your web server on port 8080, it could look more like:

http://101.23.4.56:8080/hi2.php
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-23-2009 12:49
Ok, before i put in the ip it gave me errors, but now it gives me nothing. It shows that the object is saying something but it's blank. Is there something wrong with the code? Just in case, how do I find what port I'm on.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-23-2009 13:21
the port that your server runs on is specified in the config file (httpd.conf for default apache builds) there's a line that says port and there's probably another reference in the virtual server section... both need to agree
_____________________
|
| . "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
02-23-2009 14:16
looking at it now, is the ip looking number that's in the httpd.conf next to the port what I'm suppose to use or the ip in the computer, cause they're differnent.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-24-2009 02:07
the line
Listen xx.xx.xx.xx:80
is the key here (although port numbers for any virtual hosts should match)

regardless of what your netside IP address is, the IP in that file should match the IP of the machine you're on.

Presumably you'll redirect any requests on that port to that computer, in your router (assuming you're using one) and allow them in your firewall. if you do use a router, and use a port forwarding feature, make sure you use the the port specified in the router to access it from the web, and the the redirect_target port in your config

sorry can't help with specific routers or firewalls, check their homepages for configuring those

oh and this might help you
http://httpd.apache.org/docs/2.2/
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-25-2009 11:57
It could also be that you have an error somewhere. Check your web server's log file and see if there is anything obvious there.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-25-2009 12:56
I found this:

[Wed Feb 25 14:33:48 2009] [error] [client 127.0.0.1] script 'C:/wamp/www/h1i.php' not found or unable to stat

what's [client 127.0.0.1]
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-25-2009 13:20
not that i can see, I can see errors of when I put names incorrectly and what it does everytime it starts up and shuts down but nothing else.

Where would i go to see accesses to the code. To see if SL is getting to it.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-26-2009 09:06
Hmm. Try temporarily replacing your script with:

CODE

<?php
echo "Hello World!";
?>


And see if that comes back to SL.
Angela Talamasca
VR Hacks
Join date: 20 Feb 2007
Posts: 58
02-26-2009 09:35
From: Hewee Zetkin
Hmm. Try temporarily replacing your script with:

CODE

<?php
echo "Hello World!";
?>


And see if that comes back to SL.

Or, before trying to send the request via the SL client, simply go to that url via the web. And, if nothing shows up, turn on php error logging (see php.ini and search for "log_errors";). Then, dep upon whether or not you want to display the errors on the page, set your "display_errors" accordingly. If you choose not to display them to the web page, the result should be written to your /var/log/httpd directory, in a file called php_error_log. You can also find your server error_log in that directory as well. Which may help you to identify the problem.

In other words, testing your php from the web first you can ensure your web site is set up correctly and that your code is working as expected. At which point you can make your calls from your script. Btw, and aside, don't forget to escape the request strings in your llHttpRequest call. Otherwise you will end up with an empty http response.
_____________________

Blog: http://blog.vrhacks.net
AUSL: http://www.avatarsunited.com/avatars/angela-talamasca
AUBM: http://www.avatarsunited.com/avatars/angela-talamasca-blue-mars
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-26-2009 09:39
Yes. Those are great ideas too. And I believe llHTTPRequest() returns a status code of 499 (or something like that) if you have illegal characters in the URL, so you might check the HTTP status code as well as the returned content body.
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
02-26-2009 10:30
How do I escape the request strings in the llHTTPRequest call?

Is it possible to see my scripts from another computer? After I download WAMP to another computer, can i have access to wamp files in the other computer?

The current php code i'm using is:
CODE

<?php
$string_val = "some_value";

echo $string_val;
?>
CODE

and it's still sending me blanks

Also the when I type localhost/hi1.php in the web browser it gives me the answer but not when I type 000.00.000.000/hi1.php whether the zeros are my ip address or the one in the httpd.conf
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-26-2009 15:19
had forgotten, but was reminded (rudely) that some routers have pass through problems when the request and the sever reside on the same internal network using an external name or IP, effectively blocking access from your own computer. which makes testing very annoying. use site that can grab and show full headers and response to make sure you're set up properly for the outside internet (or a friend, but that can get annoying for them) and make an entry in your hosts file for yourself.
_____________________
|
| . "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
03-03-2009 11:49
I have finaly got it to work. Thanks to everyone that helped. Now I need to know how SL can send input to php so i can use it in php code e.i. SL sends 1 as input, php gets the 1 and does x = 1 and then does x + 2 = y and print(y).
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
03-03-2009 12:51
take alook at this post :

/54/0d/308221/1.html
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Zeta Eizenstark
Registered User
Join date: 20 Aug 2008
Posts: 79
03-04-2009 12:53
When I tried it like this:
http_request_id = llHTTPRequest("url", [HTTP_METHOD,"POST"], "toucher=" + x);

it didn't work, it said in the php code that toucher was undefined but like this:
http_request_id= llHTTPRequest( "url", [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],"toucher=" + x);

it worked, so, do I have to have the HTTP_MIMETYPE for it work?
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
03-04-2009 14:49
think about this:

llHTTPRequest( string url, list parameters, string body );
|the function|---|the address|-|papams |-|Data|


HTTP_MIMETYPE = "text/plain;charset=utf-8"

"text/* MIME types should specify a charset. To emulate HTML forms use application/x-www-form-urlencoded. This allows you to set the body to a properly escaped (llEscapeURL) sequence of <name,value> pairs in the form var=value&var2=value2 and have them automatically parsed by web frameworks "

if you are sending data via http and like the wiki says especific to send ""text/* MIME types should specify a charset."
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
1 2 3