PHP Not waiting for script to finish.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
huzzak
Forum Newbie
Posts: 3
Joined: Sat Dec 05, 2009 7:08 pm

PHP Not waiting for script to finish.

Post by huzzak »

Hello. I'm trying to write a simple php frontend for a jython program. Here is the php file:

<?php
$cmd = 'jython interactiveNER.py';
$html = `$cmd`;
echo $html;
?>

The problem is that the jython script takes about ten seconds to run and the php script isn't waiting for it to finish and simply returns a blank page.

I've verified that the command I'm giving it runs from the shell. What do I need to do to get php to wait?

Thanks,

Joshua.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: PHP Not waiting for script to finish.

Post by Weiry »

have you tried sleep():

Code: Select all

$cmd = 'jython interactiveNER.py';
sleep(10);
$html = `$cmd`;
echo $html;
 
huzzak
Forum Newbie
Posts: 3
Joined: Sat Dec 05, 2009 7:08 pm

Re: PHP Not waiting for script to finish.

Post by huzzak »

I tried sleep() with a value up to a minute (it doesn't take that long for the script to run) and the results were negative.

I modified the script so that it would make a file on the directory when run to make sure it was actually being run. The file wasn't created, so it doesn't appear to even be running. Hm.

Is exec somehow limited in what it can run? What else could be the problem?

Thanks,

Joshua.
huzzak
Forum Newbie
Posts: 3
Joined: Sat Dec 05, 2009 7:08 pm

Re: PHP Not waiting for script to finish.

Post by huzzak »

It turned out that jython was expecting a $HOME environment variable and couldn't find it. I added that to the command and it runs as expected. Thanks for your help, Weiry.

Joshua.
Post Reply