Merging multiple PHP script into a single file

前端 未结 6 2006
礼貌的吻别
礼貌的吻别 2021-02-05 07:59

I have a PHP script which includes one or two other libraries it depends on using the \'include\' statement. To make it more easily portable, I would like to someho

相关标签:
6条回答
  • 2021-02-05 08:25

    The PHP packages ScriptJoiner or even better JuggleCode might help:

    • http://packagist.org/packages/codeless/scriptjoiner
    • http://packagist.org/packages/codeless/jugglecode

    Both are built upon PHP-Parser (http://packagist.org/packages/nikic/php-parser), which makes it very easy to join scriptfiles.

    0 讨论(0)
  • 2021-02-05 08:30

    There's no built in way to do that. I would recommend packaging your code up into a directory and distributing it that way. I do this with PHP, I place the code into a directory "something.module", and then have iterate through a modules directory, including the main file underneath each .module directory. But for something more simple, you could just have a structure like:

    my_package/
      my_package.php
      include1.php
      include2.php
    

    my_package.php would include(realpath(dirname(__FILE__).'/inclue1.php')). All other scrits would just have to include('my_packahe/my_package.php')

    0 讨论(0)
  • 2021-02-05 08:35

    phc allows this. Just run it with the --include flag, and it will combine all your code (well, every argument to an include, require, etc) into a single PHP file.

    If you like, it can also compile it, but that's not required to combine them all into a single file.

    0 讨论(0)
  • 2021-02-05 08:37

    You could write a custom script that opens all the files, removes the opening and closing tags, and concatenates them together and saves as one file. should be pretty easy to do.

    Or you can use a php compiler. It will do a bit more than what you are looking for, but if you just want one file, you run your dev project through one of these.

    • http://www.phpcompiler.org/
    • http://www.roadsend.com/home/index.php?pageID=compiler

    You might also be able to use the built in php bytecode compiler to compile everything to byte-code and stick it in one file.

    • http://us.php.net/bcompiler
    0 讨论(0)
  • 2021-02-05 08:42

    Newer versions of PHP support a concept similar to jar files in java. Take a look at phar. You could package all of your application files into a single archive and run that.

    0 讨论(0)
  • 2021-02-05 08:48

    Manually, you just remove all references of include/require, and "concatenate" the files together. you should also strip the open and end tags ('<?php', "?>") before concatenation, and add them in the final file.

    For one or two small libraries, it should - hopefully - "just work"...

    0 讨论(0)
提交回复
热议问题