Skip to content
/ ph7 Public
forked from symisc/PH7

symisc/PH7 split into original source files for better readability and maintainability

License

Notifications You must be signed in to change notification settings

lhsazevedo/ph7

 
 

Repository files navigation

PH7, Un-amalgamated

Fork of PH7, split into original source files for better readability and maintainability.

Note

This project is for educational purposes and to provide an accessible version of the PH7 source code, and may not be suitable for production use.

About

PH7 is a fast, embeddable PHP engine written in C, supporting PHP 5.3 features and extensive built-in functionality.

Features

  • Embeddable: Integrate PHP into C/C++ applications.
  • PHP 5.3 Support: Includes modern PHP constructs and syntax.
  • Thread-Safe: ANSI C compliant, suitable for various platforms.
  • Rich Functionality: Over 470 built-in functions.

For more details, visit the original PH7 repository.

Quick Start

Building the Executable

The provided Makefile builds the PH7 executable by default, including math functions.

To build the executable:

make

To build the executable without math functions:

make PH7_ENABLE_MATH_FUNC=0

Running the Executable

After building, you can run the PH7 executable with any PHP script. Here is an example using a test script:

./build/ph7 script/hello_world.php
# Hello World from PH7

PHP Test Scripts

The script directory contains over 70 PHP test scripts. You can run these scripts using the PH7 executable to see various features and functionality in action.

Using the Library

If you need to integrate PH7 into your C/C++ applications, you can use the PH7 library.

Building the Static Library

To build the PH7 static library:

make lib

The static library libph7.a will be created in the build directory.

Example Usage

Here is an example of using the PH7 library in a C program:

// ph7_test.c

#include <stdio.h>
#include "ph7.h"

#define PHP_PROG "<?php echo 'Hello World'; ?>"

static int output_consumer(const void *output, unsigned int len, void *data) {
    printf("%.*s", len, (const char *)output);
    return PH7_OK;
}

int main(void) {
    ph7 *engine;
    ph7_vm *vm;

    ph7_init(&engine);

    ph7_compile_v2(engine, PHP_PROG, -1, &vm, 0);

    ph7_vm_config(vm, PH7_VM_CONFIG_OUTPUT, output_consumer, 0);
    ph7_vm_exec(vm, 0);

    ph7_vm_release(vm);
    ph7_release(engine);
    return 0;
}

Compile with:

gcc -o ph7_test ph7_test.c -Iinclude -Lbuild -lph7

And run:

./ph7_test
# Hello World

See the examples directory for more usage examples.

Contributing

Fork, improve, and submit pull requests. Contributions are welcome!

About

symisc/PH7 split into original source files for better readability and maintainability

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 96.6%
  • PHP 3.4%