Is it possible to convert PHP to binary mode (compile) and run it in all standard web servers?
There are various PHP accelerators that cache the compiled byte code the interpreter produces. Not sure if they will run without the source still on the server though - I've never tried!
One Facebook developer is working on a compiled form called "Hyper-PHP", and it's not even clear if that will be an open system once complete, but no solution exists yet.
PHP Will never be a compiled Language. It will stay as an Interpreted Language.
#Matchu Facebook is just Promoting their site, so this is just an Promotion action of Facebook
There is a number of tools that will convert your php source to bytecode and allow you to protect your source code. Some of the more popular ones are Zend Guard by Zend and Ion Cube encoder. You will still need their respective loaders installed on the target server for them to function.
Related
ionCube stores php files in encrypted format and it is installed as php extension but what i want to know is when I request the encrypted php file from non-encrypted php file how does php compiler executes it.
Does it send the encrypted file to ionCube server and get the original file and compile that or there is something else.
Means how the communication is going on between our server and ionCube. I guess it is through curl but i want to know how it works.
As you may have picked up on now, original code is never obtained, and processing is based on bytecode.
Here's some high level information that may help.
PHP Extensions
PHP has two types of extensions, module extensions such as CURL that typically wrap external APIs and expose their functionality via new PHP functions, and PHP engine extensions. Though the distinction isn't set in stone, engine extensions tend to interact with PHP's compiler and execution engine, though they may add new PHP functions too. ionCube is an engine extension that also adds PHP functions for its API and also to support ionCube24, though used also to be installable as a module extension using dl(). Both kinds of modules are shared libraries, and a single line to the php.ini file is used to add an extension to PHP, with PHP making use of OS functions to dynamically link the library into the running process.
Hooks
PHP has internal hooks that allow an extension to intercept the compile and execute stages of source file processing. An extension might use these simply to perform additional steps before or after regular processing, or replace the usual processing entirely. The ionCube Loader uses the compile hook to examine a file before the PHP engine compiles it, and takes over the task of processing the file if it is an ionCube file. The result of either reading an ionCube file or normal compilation is ultimately bytecode, however ionCube bytecode is non-standard, and with version 9 it may still be encrypted or unavailable for other reasons after initial processing of a file. As the standard execution engine cannot process ionCube bytecode, the Loader also uses the execution hook to take over execution of the compiled code if it was read from an ionCube encoded file.
A further task of the Loader is to allow files produced for certain older version of PHP to run on newer versions, and where necessary the Loader performs on the fly transformations of the compiled code to make it usable on whatever version of PHP is running. PHP internals change significantly from time to time, most recently and most significantly between PHP 5 and 7, making this a challenging but important task for end user experience.
Processing of ionCube files does not require communication with outside servers, however since version 9, code can be protected with encryption keys that only exist when created at runtime by the PHP application itself, and an application developer may write PHP code that makes external calls to obtain data for constructing the decryption keys when required.
Encoded files
In terms of the files themselves, early PHP encoding tools of this type in essence compiled to bytecode and serialised this form directly to files. There was little knowledge and interest in PHP internals among developers in general, and this approach gave good protection and excellent performance. When interest first emerged in producing bytecode decompilers from a hacker group in China called the "Blue Wind" around 2006 ish, simply compiling to bytecode was clearly no longer acceptable. To varying degrees, tools such as ionCube then added more protection around the bytecode to hamper the task of successful reverse engineering. Though steps can be taken to limit the effectiveness of decompilation even if bytecode is recovered, the success at code protection still depends fundamentally on the ability to hide the necessary decoding key(s) though, and all encoding tools of this type store such a key in the encoded file itself.
In evolving code protection for ionCube version 9, a challenge was to address the limitation of stored keys, and the ability to encrypt code without storing the necessary decryption key statically anywhere was the obvious and necessary next step. This was added as a feature called "Dynamic Keys".
Hopefully that gives some insight into how ionCube and in some respects similar tools work. For more detailed knowledge of engine extension implementation, I'd recommend looking at the source code for the PHP OpCache and also Derick Rethans Xdebug.
Disclosure: I am associated with ionCube.
I have developed a PHP web application, but a client insists on a real Windows application, since he doesn't like running the software inside a browser.
Are there any solutions for this, any compilers to turn a web project into a Windows exe ?
I have looked at Phc-Win , but that seems more suited for small command line utils, not for entire web-applications...
UPDATE:
just found this myself, both look quite promising...
http://www.zzee.com/phpexe/
http://www.exeoutput.com/index.php
There's no tool for this, short of a simple wrapper app that embeds a browser inside an otherwise normal application window. Your PHP app would have to be completely re-written to include ALL of the overhead code necessary to build a GUI - basically all the 'display' stuff that a browser does automatically, would have to added to your app.
Well some of you did not google good enough:
http://www.appcelerator.com/products/titanium-cross-platform-application-development/
Supports most of the "web-languages" to write native Applications.
Tutorial Reference for Appcelerator: http://appceleratortitanium.com/tutorials/3-appcelerator-titanium-tutorial-beginners.html
Quote:
"Q: What languages can I use to make desktop apps?
A: Javascript, PHP, Python, Ruby, HTML, HTML5, and CSS."
Not exactly what you are looking for: http://www.roadsend.co/home/index.php?pageID=compiler
You may look into "HipHop" (made by Facebook): Converts PHP to compileable C++-
There's a tool for this. :-) I never used it but you can try this: Winbinder.
It is simple to compile your PHP source code into an executable. Facebook released a compiler for PHP in early-2010, called HipHop, which aims to create C++. You could then compile this code, for example using gcc, to machine-code.
The more difficult point for a complex Web-App like yours is the user interface. When compiling the way I described above, the application can be run from command line - this might work for simple tasks, but not, if your application returns HTML.
One possibility to solve this problem is PHP-GTK. PHP-GTK is a API for GTK (the graphical user interface used by Linux Ubuntu by default), written in PHP. Using this solution would have to read some documentation about this API, and you would need to rewrite some parts of your program, but it would probably be the most beautiful solution, because it would create a "native" experience.
Another possible solution could involve Adobe AIR, which lets your create programs for the desktop, using HTML, CSS and JavaScript, but I don't know if and how this would work together with your compiled PHP.
Please also note that it isn't absolutely necessary to compile your PHP for it to run on the client's computer; You could also ship the PHP-interperter right with your (uncompiled) PHP-script. Of course, compiling brings benefits, such as faster execution of the program.
-- André
I was whatching facebook's development steps and getting codes live , i think they are making their script as a single binary and pushing a single file. We got a portal with alot of files inside which coded with PHP . is there any encoder or compiler can bundle all files in single one ?
While we are pushing our codes to our servers when renaming folder or extracting files and override , it starts to give error spam.
Also any solution or approach to send the webpages alive without getting any error are welcome.
thanks
You probably need PHAR
FaceBook use a tool named HipHop which compiles PHP into a single binary executable.
For Windows, Linux and FreeBSD there's Roadsend PHP Compiler. It truly compiles PHP source code into native binary format. No interpreter is required.
They claim: "Roadsend PHP is a free, open source implementation of the PHP language. It includes a compiler that produces native binaries (no interpreter required). Roadsend Compiler can build online web applications with Fast/CGI, offline web applications with an embedded web server (MicroServer), and console applications."
They say: "Applications compiled with the Roadsend Compiler do not require Zend or any other interpreter to execute. Roadsend is not affiliated with Zend or the PHP Group and does not share (nor is it derived from) the same code base as their PHP implementation. Roadsend PHP is an entirely new implementation of PHP that is syntactically and semantically compatible with PHP Group's PHP 5.2.x and the Zend Engine 2." – Sebastián Grignoli 41 secs ago edit
"How do I know that my application won't be decompiled back to the PHP source file?"
"The compiling of a PHP application with the Roadsend Compiler is much the same as compiling a C file to binary format. The program goes through a process that converts the plain text source into a binary format that is suitable for the processor to execute, and which is extremely hard to decompile back to any sort of high level programming language."
I'm looking to protect small parts of my source code from being read when it is installed in other servers. Our created software consists of an engine, which is entirely copyrighted and an open source UI layer, which is released as open source.
That engine works with many API calls to our central server and is encrypted, but if source code of the engine can be read then that causes problems for data integrity when information is sent or received from central server. As a result we need the engine source code to be both fast and not readable.
I know that APC can cache bytecode and is very fast, but can I somehow convert the source code to bytecode and release it that way directly, without needing APC? As in, convert PHP source code to bytecode without requiring to install additional extensions to the other server?
I'm not looking for software such as IonCube or Zend Guard or any obfuscators.
Any help would be appreciated, I read through a handful threads here about compilers and obfuscators, but nothing that seemed to be the solution.
You could use apc_bin_dumpfile to store your files' generated bytecode and then redistribute it. Other platforms must have apc installed to be able to read it using apc_bin_loadfile.
You could also try compiling your code as a php extension using phc
I am developing a php application which my customers will download and install on their own servers. I know the base requirements for my application (like min. php version) but is there a way to generate a list of requirements that needed to run my application on windows or unix systems?
Thanks.
You mean, generate a list of requirements based on an analysis of your source code?
While in theory, that might be possible, I don't think such a solution exists. I think there is no way than analyzing your code by hand, with the PHP manual very close by.
Do you use GD? Then you need PHP with the GD module. Do you need to create GIF images with GD? Then you need GD, but not between versions 1.6 and (I think) 1.8. Do you use PDO? Then you need PHP > 5.1.0. And so on and so on.
In short, I'm afraid think this is going to be a manual process. Manual also as in "PHP manual" - the User Contributed Notes to each function and method are a gem, and any common cross-platform problems are usually noted there somewhere.
While you can trust that PHP x.y.z has a defined set of functions and behaviour, be sure to test well before you declare something suitable to run on a different server. IIS's support of PHP is way better now, I'm told, but the last time a ported a big PHP application over to IIS, it took me three days to work around all the mysterious bugs.
Just be aware of what you are using. For example, you should clearly communicate if you need something like .. a special database binding ( other then mysql ), xml libraries etc.., or even better, create an installer that is bundled with your software that checks that kind of stuff.
Other than that, there should be no problems concerning different servers ( apache / iis / fastcgi.. ). So to answer your question: you have to generate that list all by yourself.
As others have said, you'll need to manually keep track of special libraries and functions you're using. If you need PHP4 compatibility then you won't be able to use the built-in XML libraries for example. You can also check the list of functions added to PHP 5.
One thing I would recommend is installing WampServer if you have access to a Windows machine. Aside from being good for local development, you can download modules for most Apache/PHP/MySQL versions and test combinations.