문제

I don't do a huge amount of php work and I've never used bcompiler before but I'm migrating a php site to a new server and I can't get this working.

There seems to be a class compiled with bcompiler 'class.viewimage.php' - it contains bz compressed code 'BZh91AY&SY;iu...'

There is then a regular php file that is calling this class:

require('class.viewimage.php');
$my_image = NEW ViewImage ($MEDIALIB->Filestore);

When this code is run it just spits the text contents of the compiled class into the browser ('BZh91AY&SY;iu...'). It's the require line which is causing this. Seems to me like php doesn't magically know that this is compiled code.

To the best of my knowledge I've installed Bcompiler on the system as this code is no longer crashing (and it was crashing when I first did the migration):

if (!extension_loaded('bcompiler')) {
    $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
    dl($prefix . 'bcompiler.' . PHP_SHLIB_SUFFIX);
}

Any help appreciated.

도움이 되었습니까?

해결책

While I've had my own troubles with PHP bcompiler, using include() or require() to access compiled code (compiled using bcompiler_write_file()) on a machine with the bcompiler module installed and enabled should work.

http://us2.php.net/manual/en/function.bcompiler-read.php:

Note:

Please use include or require statements to parse bytecodes, it's more portable and convenient way than using this function.

Not only are there a multitude of bugs, but versions are incompatible with one another, which is what I'm guessing is your problem.

For example, my two (incompatible) machines:

CentOS 5.5, PHP 5.2.10, Apache 2.2.3, x86_64
----
bcompiler version   0.9.3-devs
current bytecode version    0.21
can parse bytecode version  0.7, 0.9, 0.11, 0.12, 0.14, 
0.18, 0.21

Mac OS X 10.6, PHP 5.3.3, Apache 2.2.15, i386
----
bcompiler version   0.9.3-devs
current bytecode version    0.22
can parse bytecode version  0.20, 0.22

I submitted it as a bug to the PECL package.

다른 팁

PHP considers all require/include files to be plain text, and will treat them as such until it spots either the <? (shorttag), <?php (regular tag), or <% (ASP tag) character sequences in the stream, after which it switches into PHP mode, until it hits the end of the script or the corresponding closing tag (?>, %>). As such, there's no way to have PHP treat a compiled input as program code. Even an EVAL won't help, since that just invokes the same parser that didn't trigger off the binary input in the first place.

BZipped code itself isn't executable either, unless it's been wrapped by an auto-extractor stub.

Since it would appear to be BZipped, why not try un-bzipping the file and see what you get? Maybe the class file was downloaded as a .bz2 distribution and simply got renamed. The uncompressed copy may contain the appropriate wrappers to allow execution.

I have been struggling since a long time to work with bcompiler but surprisingly i found a very easy solution where you can compile you whole website with one click. you can follow the bellow steps:-

  1. Download and install Wampserver (any edition).

  2. Download and install Wampserver PHP Addons Version php 5.2.5

  3. click on Wampserver -> PHP -> Version -> 5.2.5 from Task bar (it will change your current version of php to 5.2.5).

  4. Select Wampserver -> PHP -> extension -> php_bcompiler (it will enable bcompiler on your computer).

    Above steps are enough if you can compiler the script your own but to make it easy you can continue with next steps.

  5. Download bcompiler GUI.

  6. Select the Folder on the Bcompiler GUI and this will compiler your whole website with one click.

enjoy PHP | Enjoy Open Source

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top