RE: [PHP] Re: exec() Error
| From: | Boyd, Todd M. | Date: | Wed, 25 Jun 2008 14:32:53 +0000 |
| Subject: | RE: [PHP] Re: exec() Error | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275941@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Boyd, Todd M. [mailto:tmboyd1@ccis.edu]
> Sent: Wednesday, June 25, 2008 9:10 AM
> To: Wei, Alice J.
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Re: exec() Error
>
> > -----Original Message-----
> > From: Wei, Alice J. [mailto:ajwei@indiana.edu]
> > Sent: Wednesday, June 25, 2008 9:02 AM
> > To: Shawn McKenzie; php-general@lists.php.net
> > Subject: RE: [PHP] Re: exec() Error
> >
> > Hi, Shawn and all:
> >
> > I tried to run the script using the method you suggested for
> > Windows, but it gives me this:
> >
> > 'http' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> > I could telnet and ping to the server using #80 to where the
> script
> > calculate.php is located, though. Do you or anyone else on the list
> > might tell me why I cannot execute the script through this method?
> >
> > Here is my calculate.php, if it is of any help to you for
> > troubleshooting:
> >
> > <?php
> > // For PHP 5 and up
> > $file="http://www.mysite.com/lung.txt";
> > $handle = fopen("lung.txt", "rb");
> > $contents = stream_get_contents($handle);
> > fclose($handle);
> > $count = count(explode(" ", $contents));
> > echo "<p>There are <b>" . $count. "</b> words in
> > <b>" . $file .
> > "</b></p>";
> > ?>
>
> Alice,
>
> exec() is for executing binary commands over an interface that your
> operating system inherently understands, such as its own file system.
I
> seriously doubt either machine in question is equipped to handle URLs
> from the command line without invoking a web browser.
>
> As I said before, you should investigate cURL or AJAX to push the info
> to your remote script, and then use exec() from the remote machine to
> execute the client's program which is, as I understand it, housed on
> the
> remote script's machine.
<?php
// local script
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL,
'http://www.mysite.com/script.php?param=value');
curl_exec($curl_handle);
curl_close($curl_handle);
?>
-
<?php
// remote script
$param = $_GET['param'];
$output = array();
$returnval = 0;
exec("/usr/bin/command " . $param, $output, $returnval);
// deal with return value/output here
?>
HTH,
Todd Boyd
Web Programmer