Giter Club home page Giter Club logo

phpy's Introduction

简体中文

phpy

A library for inter-calling Python and PHP. You can use Python functions and libraries in PHP, or use PHP packages in Python.

See documents: docs/en/README.md

Supports Linux/Windows/macOS Not support Python multithreading or async-io features

py2php

py2php is online utility that will auto-translate python code into PHP code.

Calling Python from PHP

Compile and install phpy.so as an extension, and append extension=phpy.so to php.ini.

PHP Example:

$os = PyCore::import("os");
$un = $os->uname();
echo strval($un);

Calling PHP from Python

Simply import it as a C++ Mudule.

Python Example:

import phpy
content = phpy.call('file_get_contents', 'test.txt')

o = phpy.Object('redis')
assert o.call('connect', '127.0.0.1', 6379)
rdata = phpy.call('uniqid')
assert o.call('set', 'key', rdata)
assert o.call('get', 'key') == rdata

Implementation

It creates ZendVM and CPython VM in the process at the same time, and directly uses C functions to call each other in the process stack space.

The overhead is only the conversion of zval <-> PyObject structures, so the performance is very high.

In the benchmark test, we created a PyDict and executed PHP code and Python code to read and write 10 million times respectively.

The performance of phpy writing PyDict with PHP code is 14% higher than the native Python, and the read performance is 25% higher.

More details: docs/en/benchmark.md

phpy's People

Contributors

matyhtf avatar he426100 avatar heelie avatar netyum avatar baicaiit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.