Git Product home page Git Product logo

runpy's Introduction

runpy - Run Python from PHP

Module for PHP to run Python within same memory space. Using CPP Python API. Module uses JSON serialization for messaging between PHP and Python.

What it does?

The module is somewhat efficient solution for following questions:

  1. How to call Python from within PHP?
  2. Passing value from PHP script to Python script?

For complex cases where you may have massive PHP and Python code base, and want to marry them both.

How it works

PyClass is a class which is actually a Python module.

Methods of the PyClass are calling underlying Python module.

All arguments and response are serialized with JSON, please make sure arguments and result can be serialized.

Check Tensorflow example from tests.

Initialization

<?php 
// First  argument - alias is in-memory reference to python module and whatever was initialized.
// Second argument - module to take and use for future calls;
// Third  argument - on-time preparation, will be called one if alias does not exist. 
$c = new \PyClass('__','__main__',"from time import time,ctime\n");

$time = $c->time(); // call with empty array of arguments.

Constraints

EVERY FPM/Apache worker will have its own Python Runtime, which will survive after PHP request execution.

Console script will run one PHP and one Python.

Dependencies

PHP-CPP Library enables C++-based class for PHP and magic method calls.

Python C API allows communication with Python.

Known limitations

Keep eye on resource utilization, Tensorflow with GPU may fail to initialize because of memory limits.

runpy's People

Contributors

kirmorozov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.