Welcome to WebmasterWorld Guest from 52.91.39.106

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

run PHP script from Perl

I want to run a PHP script and then process the results

     
12:44 am on Mar 6, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 1, 2004
posts:14
votes: 0


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:


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.)

I'm puling my hair out over this one. Any clues?

8:00 am on Mar 6, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2004
posts:4
votes: 0


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
3:51 pm on Mar 6, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 1, 2004
posts:14
votes: 0


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

#!/usr/local/apache/bin/httpd

without success. I'm waiting on my host for the correct path to the php interpreter.

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

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
;

chdir 'path/to/file';
while (-z 'recentposts.txt') { }

It works but the rest of the perl script doesn't wait for the file to be written and so the file is unavailable to be processed. The while loop was added in an attempt to get the rest of the script to wait, but it seems to go into an endless loop and not proceed. I also tried POSIX::pause, wait and sleep. Oh deary me....

9:44 pm on Mar 6, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 1, 2004
posts:14
votes: 0


I got it going! I had some hints from my host:

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:

#!/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. Instead use the first line you mentioned:

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

and then, open the file that the PHP file outputs from the PERL script.



I had to tweek a few things first (set permissions to 744, correct some includes paths in the php) but it worked!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members