• Stars
    star
    1,389
  • Rank 32,542 (Top 0.7 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library to build PHP extensions with C++

PHP-CPP

Build Status

The PHP-CPP library is a C++ library for developing PHP extensions. It offers a collection of well documented and easy-to-use classes that can be used and extended to build native extensions for PHP. The full documentation can be found on http://www.php-cpp.com.

Watch out: PHP 7 only! This library has been updated to work with PHP versions 7.0 and up. If you wish to create extensions for older PHP versions, use the PHP-CPP-LEGACY library instead. The PHP-CPP and PHP-CPP-LEGACY library have (almost) identical API's, so you can easily port extensions for PHP 5.* to PHP 7 and the other way around.

ABOUT

PHP-CPP is created and maintained by Copernica (www.copernica.com). We write our code mostly in PHP and C++ and needed an effective way to combine these two languages. That's where PHP-CPP comes in. Do you appreciate our work and are you looking for other high quality solutions?

Then check out our other solutions:

The power of PHP-CPP

Unlike regular PHP extensions - which are really hard to implement and require a deep knowledge of the Zend engine and pointer manipulation - extensions built with PHP-CPP are not difficult to develop at all. In fact, the only thing you need to do is write a function in C++, and the PHP-CPP library uses all the power offered by C++11 to convert the parameters and return values from your functions to/and from PHP:

Php::Value hello_world()
{
    return "hello world!";
}

The function above is a native C++ function. With PHP-CPP you can export this function to PHP with only one single C++ method call:

extension.add("hello_world", hello_world);

Working with parameters and return values is just as easy:

Php::Value my_plus(Php::Parameters &params)
{
    return params[0] + params[1];
}

The method call to export the above C++ function:

extension.add<my_plus>("my_plus", {
    Php::ByVal("a", Php::numericType),
    Php::ByVal("b", Php::numericType)
});

The PHP-CPP library ensures that the variables from PHP (which internally are complicated C structures), are automatically converted into integers, passed to your function, and that the return value of your "my_plus" function is also converted back into a PHP variable.

Type conversion between native C/C++ types and PHP variables is handled by PHP-CPP, using features from the C++11 language. It does not matter if your functions accept strings, integers, booleans or other native parameters: PHP-CPP takes care of the conversion. The return value of your function is also transformed by PHP-CPP into PHP.

More complicated structures can be handled by PHP-CPP as well. If you would like to return a nested associative array from your function, you can do so too:

Php::Value get_complex_array()
{
    Php::Value r;
    r["a"] = 123;
    r["b"] = 456;
    r["c"][0] = "nested value";
    r["c"][1] = "example";
    return r;
}

The C++ function above is equivalent to the following function in PHP:

function get_complex_array()
{
    return array(
        "a" => 123,
        "b" => 456,
        "c" => array("nested_value","example")
    );
}

More information and more examples are available on the official website: http://www.php-cpp.com.

More Repositories

1

AMQP-CPP

C++ library for asynchronous non-blocking communication with RabbitMQ
C++
829
star
2

REACT-CPP

C++ event loop library. Wrapper around libev that utilizes lambda's and callback functions to notify you when filedescriptors become active and/or timers expire.
C++
142
star
3

PHP-JS

A library to integrate the Google V8 Javascript Engine in PHP
C++
111
star
4

PHP-CPP-LEGACY

The PHP-CPP library for PHP 5.*
C++
28
star
5

REACT-PHP-CPP

Event loop library for PHP implemented in C++. Support for asynchronous non-blocking sockets, DNS lookups and database connections
C++
25
star
6

SMART-TPL

Library to compile Smarty like templates into native code.
C++
24
star
7

REACT-CPP-MYSQL

C++ asynchronous mysql library on top of the REACT-CPP library. Uses lambdas and callbacks to return query results.
C++
22
star
8

DNS-CPP

Asynchronous DNS library in C++
C++
18
star
9

Documentation

Documentation of the Copernica websites
HTML
14
star
10

REACT-CPP-MONGO

C++ asynchronous mongo library on top of the REACT-CPP library. Uses lambdas and callbacks to return query results.
C++
12
star
11

REACT-CPP-CURL

C++ asynchronous cURL wrapper on top of the REACT-CPP library. Uses lambdas and callbacks to return query results.
C++
11
star
12

mailerq-docker

Dockerfiles for MailerQ
Dockerfile
8
star
13

VARIANT-CPP

Simple script-language like variable class that can be used to store different scalar types, as well as associative arrays and regular arrays
C++
6
star
14

REACT-CPP-AMQP

Library to work with the RabbitMQ broker using the REACT-CPP event loop
C++
4
star
15

http-signatures-php

Repository containing an example to verify request security, even if the message is being sent over a compromised channel.
PHP
4
star
16

Yothalot-PHP

The PHP extension to give you an easy to use interface with yothalot
C++
3
star