exec() question

    Date: 02/06/08 (PHP Community)    Keywords: php, database

    Has anyone had any luck running exec() in the background?

    I'm using php to initiate a perl script using exec with the following...

    exec('cd /usr/local/www/data/site/parse; perl parse_dbf.pl "'.$var1.'" "'.$var2.'" "'.$var3.'"');

    now that parse dbf.pl is doing a lot of various database updates and takes several minutes to run, and since the php page that's running it is waiting for it to finish, it dies before completion.
    I also don't want to do something like set_time_limit(), because that's just messy and hangs the page.

    Looking at the php docs for exec, I see "If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends."

    This sounds like exactly what I want it to do, but I'm not having any luck getting it to run.

    I've been googling for ideas, but nothing has worked yet. My most recent attempt (and there have been many variations) looks like:

    exec('cd /usr/local/www/data/site/parse; perl parse_dbf.pl "'.$var1.'" "'.$var2.'" "'.$var3.'" > holdfile.txt 2>&1');

    It quickly executes the php page, but doesn't actually run the perl.

    I'm stuck. Has anyone had luck with this? Any ideas?

    Thanks

    _________

    edit: This seems to work (although for some reason without changing the set_time_limit(), it only changes 70 of the 1657 records it's suppose to edit. Anyway, I'll figure that out. Thanks.

    exec('cd /usr/local/www/data/site/parse; perl parse_dbf.pl "'.$var1.'" "'.$var2.'" "'.$var3.'" > /dev/null 2> /dev/null & echo $!');

    Source: http://community.livejournal.com/php/611669.html

« php/linux permissions || Looping through data,... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home