PDA

View Full Version : Executing a script in a subdomain from another


click
10-11-05, 12:36 PM
I have a php script using fsockopen() to POST data to a perl script residing in a 'powweb easy' subdomain on the same server.
I understand this function timing out has something to do with load balancing?

I have read all the other threads on this issue and still cant come up with a solution.

I cant use the http://localhost.mydomain.com approach because the perl script is in a subdomain.
I tried extras' suggestion of the symlink, however i get a 500 error (Premature end of script headers). I'm guessing that this is because the symlinked perl script calls other scripts which are not?
I have tried running the php script on another cluster, but got the same problem.
I cant run the php script on another server because it requires access to a powweb database.

any ideas/help would be greatly appreciated.

extras
10-11-05, 12:52 PM
Using include(http://localhost .... ) type of things is wasteful way to do it.
Depending on the script, narmal scripts can be invoked via shell rather than going through socket and http.

Example of invoking cgi script from php using backtick (shell commnad).

<? echo `export QUERY_STRING='abc=12&xyz=whatever'; ../subdom/htdocs/script.cgi 2>&1;`; ?>


Some scripts requires a lot more CGI Env variables.

Also, it's easy to place dummy wrapper cgi in the accessible path , and then use 'require' to include the real script.

So, there are many ways to do, but it all depends on what you want and the script in question.
But it's a sign of bad planning if you need lots of walk around like that.

click
10-11-05, 01:23 PM
thanks for the quick reply extras.

Bascially, im retrieving a list of my users from a database, then POSTing their details one by one to the cgi script handling user signup for a helpdesk app. Then they all get confirmation emails etc.
It worked fine for the occasional sync when i was on different servers.

That wrapper idea looks good. I will give it a go.

I don't know if shelling the script with a query string will work, but i will try it if the wrappering fails.
Im not very familiar with perl. Does it treat variables passed in the query string differently than POST variables (which the script is expecting)?

extras
10-11-05, 01:58 PM
A Perl script may treat POST data differently. It depends on the script.
Sending data from browser's address bar will tell you if GET method would work with the script.
(Or you can make a copy of posting form, and change <action ...> tag to use GET instead of POST.)

click
10-11-05, 02:36 PM
ohhh kay.

Firstly... the shelling method.
Got me results like so:
HTML::Template->new() : Cannot open included file error.tmpl : file not found. at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Template.pm line 1618
HTML::Template::_init_template('HTML::Template=HAS H(0x80bf674)') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Template.pm line 1191
HTML::Template::_init('HTML::Template=HASH(0x80bf6 74)') called at /usr/local/lib/perl5/site_perl/5.8.6/HTML/Template.pm line 1085
HTML::Template::new('HTML::Template', 'filename', 'error.tmpl') called at /www/g/gotooutbackc/guru/htdocs/pdesk.cgi line 39
Content-Type: text/html
I have no idea whats going on there... but it doesn't look too promising...

The wrapper method. I created a .cgi with
#!/usr/bin/perl

require /www/m/myaccount/sub/htdocs/pdesk.cgi
(no idea if this is correct as i've never written my own perl :P)

uploaded it to the main /htdocs and tried to fsockopen() on that.
It responded the same as when i symlinked pdesk.cgi to there. (internal server error - premature end of script headers)

anyway... What im trying to do just doesn't seem possible on powwebs servers.
I ended up just exporting the tables i needed to my local mysql server and running the script from here. Then i was easily able to fsockopen the cgi on powwebs servers and upload the changes to the db tables manually afterwards.
I wanted to avoid having to do this every time i wanted to sync, and i hate giving up on things, but one must sleep sometime :wreck:


Thanks again for your help extras, i learnt some interesting stuff.