Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68151 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9343 invoked from network); 18 Jul 2013 09:06:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2013 09:06:40 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.176 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.176 mail-lb0-f176.google.com Received: from [209.85.217.176] ([209.85.217.176:33980] helo=mail-lb0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/91-20914-F10B7E15 for ; Thu, 18 Jul 2013 05:06:39 -0400 Received: by mail-lb0-f176.google.com with SMTP id z5so2267365lbh.7 for ; Thu, 18 Jul 2013 02:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=n4qc2LuAt6CiEu/Ns5vRUfNyTLp9W60EKeinuZi1jBk=; b=IUXw49RUJusYvwfQPU5/H/axbdNtzKQKZbsy1mCQVLnXZS2M0D5rPEhOFi7L5Lxk26 3Css6NhOqE4xt1H+PTft9OBrxGqsO/UHM0EtWV564wjb3y2QXKcT/2R9KoqkJX/wusvy msqpVgouSAo+1h/NuCxhFbgC7Of8k/SlE9KzUmLyzoSly5T6RySwSCy7hZMFH+iOmzTV WUnXeK/dyd5clg2nzV2pVIAe87OF5wgYcWQbRCHVTt3ovOvYQ2d/Zm47CzZMP7PadvG/ krBHgnmeBGDQYWeKSOBWq0Wv0cggkg0KXK17lhPdyXMtsfq4ChWBkLpcPIaIbDi/5YG0 h0dQ== X-Received: by 10.112.34.209 with SMTP id b17mr4883587lbj.55.1374138396082; Thu, 18 Jul 2013 02:06:36 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.4.233 with HTTP; Thu, 18 Jul 2013 02:05:55 -0700 (PDT) In-Reply-To: References: Date: Thu, 18 Jul 2013 18:05:55 +0900 X-Google-Sender-Auth: gw4Xasorwz1JIutxD98rwsrqZ0I Message-ID: To: crankypuss Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=14dae93d8edef88a0504e1c586f5 Subject: Re: [PHP-DEV] execute compressed PHP command-line application From: yohgaki@ohgaki.net (Yasuo Ohgaki) --14dae93d8edef88a0504e1c586f5 Content-Type: text/plain; charset=ISO-8859-1 Hi, You may use register_shutdown_function() to clean things up after exit() http://jp2.php.net/manual/en/function.register-shutdown-function.php So simply extract files to tmp dir and delete everything after execution. I guess this is what you need. BTW, I don't think eval() is evil as long as programmers know what they are doing. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net 2013/7/18 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. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --14dae93d8edef88a0504e1c586f5--