I am building a Geocoding webservice for one our client website and need help desparately. Based on this article http://www.developer.com/tech/article.php/3557171 I have followed things and everything is working fine. Now I am trying to implement this bit http://www.developer.com/lang/perl/article.php/3566631 and am stuck. Could some one tell me in which path do I place perl package "geocode.pm", "geocodews.pl" and "geocodeclient.pl".
The directory will be defined by the URL or the file which calls the included file. For instance: http://localhost/perl/geocodews.pl wants to see the perl source file located in a directory named perl which is located in the top level of web server. If your web server's top level directory is: /var/www then the file needs to be in the directory /var/www/perl
Hi, this worked very well. Is it possible to call this perl script from php and use the returned values ( this perl script accepts US address and returns longitude and latitude)
The only way I have been able to get that to work is to call the perl script using the exec function and then parsing the results for use by the PHP program. Something like: $args = "US address"; $result = exec( "perl /var/www/perl/geocodews.pl " . $args); list($long, $lat) = split( "-DELIM-", $result); Code (markup): Change -DELIM- to whatever delimiter the perl script uses to separate the values. PHP is making a command line call to the script and retrieving the result. The perl program needs to be able to retrieve the information from the argument string. I use shift. But, if the address has spaces, this might be an issue. The perl program must be doing some kind of database call. Why not work that out in PHP?
This looks like a good idea. But how do I execute a perl code that lives in another domain. for ex. GEO DB and geocodeclient.pl lives in my home system under domain 'A.com'. The php script that requires the output of this perl script lives in 'B.com'. Hence i can't use an absolute path such as 'perl /var/www/cgi-bin/geocodews.pl'. Can I use 'perl www.A.com/cgi-bin/geocodeclient.pl'.
No. . . . but if you control the output of the perl script then you could call the script from within PHP with the proper parameters in the URL and capture the results locally. However, if the script is not under your control, you may get messed up by security measures intended to prevent the perl script from being enslaved. This approach works with machines on separate IPs. Your php program: <?php $story = file( 'http://www.B.com/cgi-bin/test.pl?this-is-my-query'); $paras = count($story); $line = ""; for ($x = 0; $x < $paras; $x++) { $line .= $story[$x]; } echo "test.pl said == > $line<br>"; ?> Code (markup): Your perl program -- test.pl #!/usr/bin/perl $query = $ENV{"QUERY_STRING"}; print "Content-type: text/html\n\n"; print "query is $query"; Code (markup): Here, perl simply returns the query -- the information after the question mark in the URL. But, it could return anything you need. PHP views this as just another file, so you can do anything you need with the generated data.