Total Pageviews

Monday, 5 June 2023

php和Java的结合体-JPHP



JPHP是一个基于 Java VM 的 PHP 编译器。 类似 javac ,可将 PHP 源码编译成 JVM 的字节码并在 JVM 中执行。

支持 PHP (5.6+)的诸多特性,JDK 1.6+, 支持Android平台。 作者表示JPHP并不是要取代Zend PHP engine 或 Facebook HHVM.

该项目目的:

    可在 PHP 中使用 Java 类库
    通过 JIT 和 JVM 来提升性能
    替换 Zend 糟糕的库,使用更好的运行时库
    在非 Web 应用中使用 PHP 语言
    字符串和线程的 Unicode

官网:http://j-php.net/

下载:https://github.com/jphp-compiler/jphp

-------------------------------------------------------

JPHP - an implementation of PHP on Java VM

jphp.develnext.org 

JPHP - an implementation of PHP

Build Status

JPHP is a new implementation for PHP which uses the Java VM. It supports many features of the PHP language (7.1+).

How does it work? JPHP is a compiler like javac, it compiles php sources to JVM bytecode and then can execute the result on the Java VM.

In Production

We develop a new IDE for beginners like Game Maker or Scirra Construct. It's based on JPHP, JavaFX, Java 8, Gradle and allows to create desktop games and apps for Linux, Windows and Mac (maybe Android and other platforms in future). The project name is DevelNext (https://github.com/jphp-group/develnext-ide), the current status and version of the project is BETA. The project has not yet been localized in English.

Goals

JPHP is not a replacement for the Zend PHP engine or Facebook HHVM. We don’t plan to implement the zend runtime libraries (e.g. Curl, PRCE, etc.) for JPHP.

Our project started in October 2013. There were a few reasons for that:

  1. Ability to use java libraries in PHP (own extensions + other)
  2. Replacing the ugly runtime library of Zend PHP with a better runtime library.
  3. Using the PHP language not only on the web
  4. Multithreading like in Java and C#.
  5. Unicode Strings (Full Support for UTF-8, UTF-16).
  6. Creating GUI Android & Desktop applications on PHP language.

Features

  • PHP 7.1+ (and many language features from PHP 7.2, 7.3, 7.4).
  • JIT (~2.5x faster PHP 5.6, ~1.1x faster PHP 7.0, ~13% slower than PHP 7.4, bench).
  • Using java libraries and classes in PHP code.
  • Unicode for strings (UTF-16, like in Java)
  • Threading, Sockets, Environment architecture (like sandbox objects in the runkit zend extension).
  • GUI (JavaFX or SWT)
  • Embedded cache system for classes and functions
  • Optional Hot Reloading for classes and functions
  • Ability to use on Android OS : jphp-android

What JPHP supports from PHP 7.2?

  • All features except RFC: Parameter Type Widening

What JPHP supports from PHP 7.3?

  • All features except RFC: Flexible Heredoc and Nowdoc Syntaxes

What JPHP supports from PHP 7.4?

  • Typed Properties 2.0 (partly, references are not supported)
  • Weak References
  • Arrow Functions 2.0 (+ multiple line syntax)
  • Allow throwing exceptions from __toString()
  • Null Coalescing Assignment Operator
  • numeric_literal_separator
  • Spread Operator in Array Expression

Own Extensions

Documentation

Getting started (Hello World)

  1. Install jphp package manager (jppm), how to install.
  2. Init new project (jppm package) with default values:
jppm init
  1. Run in console jppm start.

You will see Hello World in your console, the sources of this program will be in src/index.php.

  1. (Optional) To update jphp version of your old project:
jppm update jphp-core

How to run benchmarks?

// via jphp
./gradlew bench

// via php
php -f bench/src/bench.php

Build SNAPSHOT from sources

Use gradle install to build and install the jphp modules and libraries into the mavel local repository. After this, you can use jphp in your projects as a maven dependency.

org.develnext.jphp:jphp-<module>:<version>-SNAPSHOT

from https://github.com/jphp-group/jphp

--------------------------------------------

JPPM

JPHP Package Manager

JPPM is a packager manager for jphp like npm (js) or composer (php). JPPM will help you to build and run jphp applications.

IMPORTANT: JPPM and JPHP requires Java 8 or 9+. Download here: https://java.com/download/.

0. How to install jppm?

For Windows Users

For Linux Users

That's all! Try to check jppm in console.

jppm version

1. How to build and install jppm from sources?

  • Clone the jphp repository from https://github.com/jphp-compiler/jphp.git.
  • Open repo directory in your console and run:

On Linux (it will create link of jppm to /usr/bin/jppm, use sudo if needed):

sudo ./gradlew packager:install --no-daemon

On Windows:

gradlew packager:install --no-daemon
  • [Only if Windows] Add the jppm bin path to your system properties, use %UserProfile%\.jppm\dist for bin path.

  • Restart your console!

After all of this the jppm command will available in your console. Try to get version of jppm:

jppm version

It should print a version information about jphp.

2. How to create project (package)?

Run and select options:

jppm init
  • If you choose add AppPlugin (yes) so you can run the created package as jphp application, use start:
jppm start

It will println Hello World in your console. The php source of the package see in src/index.php.

3. How to run and build JPHP apps?

If you didn't choose the add AppPlugin option as no, use this manual.

  • Before, add AppPlugin to your package.php.yml (see plugins sections), e.g.:
name: test

plugins: 
  - AppPlugin # include app plugin
  
# ...  
  • Now, the command start, build, clean will be availble.
  • Add jphp compiler dependency to your package.php.yml:
name: test

plugins: 
  - AppPlugin # include app plugin
  
deps:
  jphp-core: '*'
  jphp-zend-ext: '*'
  jphp-httpserver-ext: '*' # add http server extension  
  • Add a bootstrap script to your app, e.g src/index.php:
<?php echo "Hello World";
  • Add the path of the bootstrap script in package.php.yml:
name: test

plugins: 
  - AppPlugin # include app plugin
  
deps:
  jphp-core: '*'
  jphp-zend-ext: '*'
  jphp-httpserver-ext: '*' # add http server extension  
  
sources:
  - 'src' # add 'src' dir as source directory (for class loader too).
  
includes:
  - 'index.php' # include php files at start up from sources directories.
  • Now, you can run jppm start to run you app.
  • And you can run jppm build to build your app with launch scripts for windows and linux!

from https://github.com/jphp-group/jphp/tree/master/packager#0-how-to-install-jppm

 

 

 



No comments:

Post a Comment