Re: [PHP-INSTALL] Executing a python script from within perl

[email protected] ("Daniel Brown")
Newsgroups php.general,php.install
Message-ID <[email protected]>
    Forwarded to the appropriate list (PHP General).  Anuj: If you're
not already subscribed, please visit http://php.net/mailinglists and
subscribe to the PHP General list, or send a blank email to
[email protected].

On Tue, Jul 22, 2008 at 11:09 PM, Anuj Bhatt <[email protected]> wrote:
> Hi,
>
>
> I'm new to PHP and just installed apache2 with php support. I'm trying
> to execute a Python script (from within php), which does take a good
> amount of time and am waiting for it to terminate so that I can process
> the output and print that out in HTML.
>
> The problem I'm having is that I can't get the PHP script to wait for
> the Python file to terminate. If I try it with a simple Python script
> say "print Hello, World!" it gets that. But anything that takes
> substantially long time, it just returns. I've tried system("myfile.py",
> $result) and $result results in a 1 and prints any subsequent prints in
> the PHP file. I also tried exec, with no luck. I've read through
> http://www.php.net/function.exec and the documentation presented in the
> "See Also" section with other commands. I haven't got anywhere yet,
> after much work. Any pointers, suggestions and fixes?

    Try this to see if your script is outputting any errors:

<?php
    exec('/path/to/python your-script.py 2>&1',$ret);
    print_r($ret);
?>

    If that works, you may just need to adjust your timeout and set
ignore_user_abort(1) to allow the Python script to keep running.  If
all else fails, and you're aware of the side-effects, go fork()
yourself.  ;-P

-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.