Lunarpages Web Hosting Forum

Author Topic: run a PHP script from a Perlscript  (Read 976 times)

Offline denby

  • Trekkie
  • **
  • Posts: 17
    • http://www.thebabywearer.com
run a PHP script from a Perlscript
« on: March 06, 2004, 06:22:19 AM »
I have a php script which processes some data from my phpbb database and outputs that data to a text file (one username per line).
I have a Perl script which opens that text file (as well as processing other data) and then combines, sorts, removes duplicates...

Anyway the point is I want to run the php script at the start of the perl script and then read its output text file.

I've tried each of the following without success:

Code: [Select]
system("/home/me/public_html/forum/report_posts.php");

`/home/me/public_html/forum/report_posts.php`;

open (PHPSCRIPT, "</home/me/public_html/forum/report_posts.php") &errorfile("report_posts.php");
@phpcode = <PHPSCRIPT>;
close PHPSCRIPT;
print @phpcode;
(The php script was written to the browser but as soon as it hit a ">" it assumed the script had finished and then just printed the literal code to the screen.)


Someone on another forum suggested the following:

Quote
try putting the path to the php interpreter at the top of the php script (the same way you put the path to perl at the top of perl scripts). On every linux server I have come accross it is /usr/local/bin/php , so you would put this at the top of your script:
#!/usr/local/bin/php


I tried that but it doesn't work either. I also tried

Code: [Select]
#!/usr/local/apache/bin/httpd

without success. What is the correct path to the php interpreter?

I also tried using an iframe to run the php script:

Code: [Select]
print <<EOF;
<iframe src="http://www.mysite.com/forum/report_posts.php" frameborder=0 scrolling="no" framespacing=0 marginheight=0 marginwidth=0 width=400 height=40>
</iframe>
EOF
;

while (-z '$CGIBINPATH/recentposts.txt') { }


The while loop was added in an attempt to get the rest of the perl script to wait until the php script had finished loading and running, but it seems to go into an endless loop and not proceed.

I'm puling my hair out over this one. :?  It's probably simple :oops: Anyone got any ideas?
"It takes a tribe to raise a child"
www.TheBabyWearer.com
-- The meeting place for babywearers --

Offline Ripta

  • Master Jedi
  • *****
  • Posts: 1271
run a PHP script from a Perlscript
« Reply #1 on: March 06, 2004, 11:00:55 AM »
Quote

I have a php script which processes some data from my phpbb database and outputs that data to a text file (one username per line).
I have a Perl script which opens that text file (as well as processing other data) and then combines, sorts, removes duplicates...


First, you need to make sure your PHP script is meant to run standalone, i.e. not on a server. You can then put the path to your PHP interpreter on the first line of your PHP file:

Code: [Select]

#!/usr/local/bin/php


Then, make sure your PHP is CHMODed correctly so that the user (you) have permission to run (execute) the PHP file. You should then be set! :)

Additionally, you don't want to open input from the PHP file itself:

Code: [Select]

open (PHPSCRIPT, "</home/me/public_html/forum/report_posts.php") &errorfile("report_posts.php");


instead, use the first line you mentioned:

Code: [Select]

system("/home/me/public_html/forum/report_posts.php");


and then, open the file that the PHP file outputs from the PERL script. :thumb:
GetAFreelancer! (This service is not affiliated with Lunarpages)

Offline denby

  • Trekkie
  • **
  • Posts: 17
    • http://www.thebabywearer.com
run a PHP script from a Perlscript
« Reply #2 on: March 06, 2004, 12:20:22 PM »
I had to tweek a few things first (set permissions to 744, correct some includes paths in the php) but it worked! :yey:  :yey:

Thanks very much. :)
"It takes a tribe to raise a child"
www.TheBabyWearer.com
-- The meeting place for babywearers --