Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68150 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6535 invoked from network); 18 Jul 2013 08:38:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2013 08:38:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=php-php-dev@m.gmane.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=fullmoon@newsguy.com; sender-id=softfail Received-SPF: pass (pb1.pair.com: domain m.gmane.org designates 80.91.229.3 as permitted sender) X-PHP-List-Original-Sender: php-php-dev@m.gmane.org X-Host-Fingerprint: 80.91.229.3 plane.gmane.org Received: from [80.91.229.3] ([80.91.229.3:60006] helo=plane.gmane.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/21-20914-F79A7E15 for ; Thu, 18 Jul 2013 04:38:24 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UzjjA-0004pG-Gt for internals@lists.php.net; Thu, 18 Jul 2013 10:38:20 +0200 Received: from 57.sub-75-220-234.myvzw.com ([75.220.234.57]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Jul 2013 10:38:20 +0200 Received: from fullmoon by 57.sub-75-220-234.myvzw.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Jul 2013 10:38:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: internals@lists.php.net Date: Thu, 18 Jul 2013 02:38:04 -0600 Lines: 37 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 57.sub-75-220-234.myvzw.com User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120714 Thunderbird/14.0 X-Archive: encrypt Subject: execute compressed PHP command-line application From: fullmoon@newsguy.com (crankypuss) I've been using PHP for linux command-line applications. Some are quite large. I've built the code to combine the mainline plus everything it calls into a single file to avoid portability issues with include libraries. I've built the code to compress the resulting file using gzdeflate after optionally stripping comments and excess whitespace. As a result, I have the uncompressed code in a variable after using gzinflate. Executing it cleanly has become an issue, and I'm looking for a solution. I see the following possible solutions: 1. Build the mainline as a function, write the decompressed code to a temp file, include the temp file, delete the temp file, then invoke the mainline function. This works reasonably well with the exception that magic constants like __FILE__ are set during the parsing of the include file. The result is that for example __FILE__ contains the name of the temp file, which causes results other than the original. I know of no way to change __FILE__ once it has been set, and if the application relaunches using __FILE__ it is attempting to invoke the now-missing temp file. 2. Build the mainline as it was originally coded, write the decompressed code to a temp file, include the temp file. The problem with this approach is that if the application issues an exit() the temp file will be left laying around. Additional issues may exist but this one is imo a show-stopper. 3. Pass the decompressed code to eval(). This approach is rather a joke due to the well-intentioned efforts of whoever chose to consider eval() a security exposure and modified echo to tell the user it is eval'ed code. Approach (1) seems the most promising but using it will require that the target applications be specially coded with regard to __FILE__ and possibly other magic constants. I really don't want to place special requirements on the coding of the target application. Suggestions would be appreciated, as I don't want to have to modify the interpreter at this point. Thanks in advance.