Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68303 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40090 invoked from network); 25 Jul 2013 14:42:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jul 2013 14:42:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.48 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.219.48 mail-oa0-f48.google.com Received: from [209.85.219.48] ([209.85.219.48:48332] helo=mail-oa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/53-05798-74931F15 for ; Thu, 25 Jul 2013 10:42:15 -0400 Received: by mail-oa0-f48.google.com with SMTP id f4so4475860oah.21 for ; Thu, 25 Jul 2013 07:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=8GyrvfTbN2xbH82+DKq1RqvQG5WyERJa7yU/ipLteoo=; b=nhUjhxnstCyg9Xq6DH9FSPlIEeP+IC0Jh29EGwkRYgMVUJu3djxd3Rjdwg0+LybeFD 59G7ezIHwzKlnXZDTSLWrkOBOG9mYEfxBLQIzpj6su0f+Z1MNCTwoeh6FOuDYpJSe9OJ sXOHQyaYLNfTVkUUI6o4CfPcA4qv+nhU2RFqU8YDGbnVCrbj3d7BBF7fkp9Ce6P4a/2q 83gT26C4NNRk+3OGqDR3PgbWo4/LXIE84Aeq9YQeqDC1TZYFvfDsAXxRaBcbMucw/TbB HAg2lxV9M8jnJbuW7/wxuKJil568RtYOWNWaz0z6rhW/TboPm7opj/kOC9Cjb8fEee/E 0Rpw== MIME-Version: 1.0 X-Received: by 10.50.44.35 with SMTP id b3mr372982igm.7.1374763332497; Thu, 25 Jul 2013 07:42:12 -0700 (PDT) Received: by 10.50.65.8 with HTTP; Thu, 25 Jul 2013 07:42:12 -0700 (PDT) In-Reply-To: References: Date: Thu, 25 Jul 2013 16:42:12 +0200 Message-ID: To: crankypuss Cc: PHP Internals Content-Type: multipart/alternative; boundary=047d7bdcab2e1579c504e25708a9 Subject: Re: [PHP-DEV] execute compressed PHP command-line application From: tyra3l@gmail.com (Ferenc Kovacs) --047d7bdcab2e1579c504e25708a9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 18, 2013 at 10:38 AM, crankypuss wrote: > 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 tem= p > file, include the temp file, delete the temp file, then invoke the mainli= ne > 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 approa= ch > 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 possib= ly > 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. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > check out http://us1.php.net/phar and http://www.php.net/manual/en/wrappers.phar.php currently this is the preferred method for shipping an application in a single file, as it is allows you to work those files and directories in the phar via most php functions as those would be normal files/directories on the disk so stuff like __LINE__ would point a valid path. for 2, you could use shutdown functions, but with phar:// you wouldn't need to extract the files, hence no need for the cleanup. ps: beware, if you try to pass these paths to external libs/application, they won't be able to work with the phar:// files of course. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --047d7bdcab2e1579c504e25708a9--