Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

http-in passing variables from php curl

Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-07-2009 03:48
Does anyone know if any special curl setopt's or such are required in sending variables form php to LSL http-in?
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-07-2009 16:25
Not sure about curl, because I don't use it. Using straight php, I set up variables within an array and use http_build_query. Then send to the prim url within HTTP Wrapper.
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-07-2009 19:09
Which http wrapper are you using to send the variables?
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-07-2009 21:53
Wrappers I've tried --
curl (which works for flickr and regapi)
file_get_contents,
fopen,
fopen with stream_get_contents

Still can't seem to get it to work...
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-08-2009 00:45
I'm using fopen and stream_get_contents, and it does work. It won't let me put the code in here though..I sent you a notecard inworld instead
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-08-2009 01:23
I tried the Dr Evil guy's snippet earlier, but that wasn't working. http://netevil.org/blog/2006/nov/http-post-from-php-without-curl

Tried again with your notecard, direct copy & paste (updating url), still doesn't work! (Manually typing in the prim url sending vars works, but can't seem to get script to send!)

Any other ideas?
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
10-08-2009 09:19
I would try using GET instead if you can, I've seen some PHP set-ups that completely screw up data POSTing.

If you need to send a large chunk of data, then you may have to use HTTP-IN to inform an object that new data is available, then have the object use llHTTPRequest to pull it from your server.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-08-2009 18:38
Neither GET nor POST work... and I'm just trying to send a very simple short 1-word variable in as test.
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-08-2009 19:30
What server are you sending it from? Some hosts you simply can't do it from, has to do with the port, is what I was told.
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-08-2009 20:44
I have my own dedicated linux (CentOS) server, so I guess the next problem is figuring out which port to open.. Are these prim url's always on the same port?
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-09-2009 06:30
geez, to be honest, I don't know lol...let me play with it. I use my own server as well, but I didn't have to do anything. It's probably got to do with outgoing firewall settings or something. I'll get back to you on the port thing, I'll reset mine a few times and see if the port changes or just the url itself.
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-09-2009 12:46
I haven't been able to get my prim url port to change, but I only have a 512m2 mainland - is it different on other parcels, or estates?

Also, what are your server specs?
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-09-2009 14:57
well, my port remains at 12046, not sure if it's the same on all servers. I'm using apache2 on Ubuntu Server.
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-10-2009 00:17
Yanno, this might be something to take up with Kelly Linden and the scripters email list. I don't understand why yours isn't working. If you were using GoDaddy or something, then I'd fully understand. This, though, I don't get.
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-10-2009 00:32
Also, after re-reading Darien's post on his pseudo DNS service, it looks like his constant port was also 12046, so my assumption is this is the port always used. Please correct me if you find out differently, though.
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-10-2009 02:01
Is your PHP configured to open more than the default ports?
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
10-10-2009 03:29
I might be wrong but since it's called http_in it probably uses port 80.
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-11-2009 03:22
Man, I don't know..I just installed PHP when I set up the server, I didn't choose anything different. It's just a standard PHP5 install.
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
10-11-2009 05:25
Standard PHP install should be able to send outgoing connections just fine, it's incoming one you would need to be wary of.

Could you post your PHP curl code, anonymised if necessary?
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-12-2009 03:51
From: Haravikk Mistral
Standard PHP install should be able to send outgoing connections just fine, it's incoming one you would need to be wary of.

Could you post your PHP curl code, anonymised if necessary?


Exactly..that's why I was thinking maybe it had to do with his outbound firewall or security settings.
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-12-2009 15:19
It seems like prim URL addresses are only on 12046

From: Ron Khondji
I might be wrong but since it's called http_in it probably uses port 80.



Also, my problem seems both in/out - file_get_contents,fsock,curl etc. all do not work (though manually typing in the url with var's in my browser works!)

From: Haravikk Mistral
Standard PHP install should be able to send outgoing connections just fine, it's incoming one you would need to be wary of.

Could you post your PHP curl code, anonymised if necessary?


as for code - i've tried things as simple as echo file_get_contents('prim url'); (nothing echos) to a bunch of snippets available on the web, which work for port 80 addresses, but not the prim url! (but, the prim url *is* valid. output and input returns on manually typing in the address into firefox...)
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-12-2009 15:19
It might be security settings - or maybe some missing setopt() ... any idea which settings I should change?

From: ElQ Homewood
Exactly..that's why I was thinking maybe it had to do with his outbound firewall or security settings.
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
10-13-2009 00:49
I wish I did. honestly, I'm not big into servers and systems. I know that the rules for outgoing packets, the output chain, can be changed. This will be done with your server's firewall or implementation of iptables, and can be configured using whatever manager or control panel you use with your server. If you are using command-line, I'm gonna be no help lol. Still, this is where I would look for the problem, in the outgoing packets rules of the server firewall. Also, you might check your router's firewall as well because that's also a possibility for outgoing packet rules and if it is set for high security may block large ranges of ports on outgoing packets.
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
10-13-2009 04:49
Have you tried using file_get_contents() with a stream-context (stream_context_create()), or curl with set-opts that provide standard browser headers? If you can copy the headers that FireFox is sending (firebug may allow you to view these) then you may be able to mimic FireFox's success. Safari will definitely show you the headers that it sends if you go into the develop menu and open the web-inspector, FireFox I'm not as familiar with.

I'd make sure you have at the very least the http_method header, and the http_header 'User-Agent', as these are the kind of things I'd expect SL to check if any, and which your PHP may not be including by default.

You should be able to get more detailed information about a stream by doing:

CODE
$myURL = "http://example.com/page";

function my_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
// Do something with the notification results here, namely check for useful $notification_code values.
if ($notification_code == STREAM_NOTIFY_FAILURE)
die ("$message (HTTP Code: $message_code)");
}

$context = stream_context_create(
array(
'http' => array(
'method' => 'GET',
'header' => "User-Agent: PHP\r\n"
)
),
array('notification' => 'my_callback')
);

echo file_get_contents($myURL, 0, $context);


Apologies if there are any typos, and you'll likely want to remove the notification parameter if you ever get this working, but that ought to give you more useful information about what's actually happening. Click quote on my post if you want the benefit of the indentation.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Complex Infinity
Registered User
Join date: 24 Mar 2008
Posts: 19
10-13-2009 21:36
file_get_content does not return anything - not even an error message. tried your exact script, with my prim url but sans the callback (compile error with callback). test prim is configured so that on either get/post my avatar receives an im and llownersay beep. i do get a beep when loading the url manually on firefox, but never via php. (grr!)

must be a port problem. see my next post for my attempt at using a php browser emulator.

From: Haravikk Mistral
Have you tried using file_get_contents() with a stream-context (stream_context_create()), or curl with set-opts that provide standard browser headers? If you can copy the headers that FireFox is sending (firebug may allow you to view these) then you may be able to mimic FireFox's success. Safari will definitely show you the headers that it sends if you go into the develop menu and open the web-inspector, FireFox I'm not as familiar with.

I'd make sure you have at the very least the http_method header, and the http_header 'User-Agent', as these are the kind of things I'd expect SL to check if any, and which your PHP may not be including by default.

You should be able to get more detailed information about a stream by doing:

CODE
$myURL = "http://example.com/page";

function my_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
// Do something with the notification results here, namely check for useful $notification_code values.
if ($notification_code == STREAM_NOTIFY_FAILURE)
die ("$message (HTTP Code: $message_code)");
}

$context = stream_context_create(
array(
'http' => array(
'method' => 'GET',
'header' => "User-Agent: PHP\r\n"
)
),
array('notification' => 'my_callback')
);

echo file_get_contents($myURL, 0, $context);


Apologies if there are any typos, and you'll likely want to remove the notification parameter if you ever get this working, but that ought to give you more useful information about what's actually happening. Click quote on my post if you want the benefit of the indentation.
1 2