Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2004, 07:54 PM   PM User | #1
benchivers
New to the CF scene

 
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
benchivers is an unknown quantity at this point
Problem with popen

I am having some problems with the popen function. I am trying to execute another php script using the popen function. The code i have written works ok (without error reporting) as I have tested it via the command line and it works fine. When using it via the command line e.g. 'php test.php' the output is successfully displayed on the screen, but when I execute test.php via my web browser, the output is not displayed. I have a feeling it's something to do with buffering, but I do not understand how it works. The code for the file 'test.php' is shown below:

<?php

$pipe = popen("php -f simpletest.php", "r");
$data = fread($pipe, 1024);
echo $data;
pclose($pipe);

?>

Any help with this matter would be most appreciated.

Many Regards,
Ben Chivers
benchivers is offline   Reply With Quote
Old 01-04-2004, 02:16 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
have you tried simply exec()ing the script... unless your script is going to take a long time to run you maybe do not need popen

<?php
exec( "php -f simpletest.php", $yaks ) ;
print_r( $yaks );
?>

or you can get error messages as well (on *nix)

$pipe = popen("php -f simpletest.php 2>&1", "r");

also with any type of shell script always use the pull path when testing as is takes away any uncertainty , e.g.

exec("/usr/local/bin/php -q -f /home/user/scripts/blah.php 2>&1");
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:21 AM.


Advertisement
Log in to turn off these ads.