Questions tagged [php-extension]

The PHP language can be enhanced through the use of extensions, which provide to PHP scripts new internal functions, classes, resource types, streams (also stream wrappers and filters) and, in general, can do anything a native program would be able to do.

The PHP language can be enhanced through the use of extensions, which provide to PHP scripts new internal functions, classes, resource types, streams (also stream wrappers and filters) and, in general, can do anything a native program would be able to do. Extensions are typically written in order to:

  • Wrap a native library, which is typically written in C or C++.
  • Implement PHP code in a language that offers more optimization opportunities, such as C, so that pages can be served faster and/or more pages can be served concurrently.
  • Implement/functions classes that, being closer to PHP's core, are able to do things that would otherwise not be possible (e.g. add/remove functions from the function table dynamically, bypass open_basedir).

PHP is written in C and has a C API available for extensions, therefore these tend to be written in that language. However, the only requirement is that the resulting extension is able to interface with PHP's APIs, handle its data structures and can be loaded by PHP's extension loading mechanism.

SWIG can be used to wrap native libraries in an easier fashion. See also PHP4Delphi, which allows embedding PHP in Delphi and other applications as well as writing PHP extensions in Delphi.

A special type of extensions, Zend extensions, are more tightly coupled with PHP and are provided with more hooks so that they can modify PHP's behavior more extensively. They are typically used to implement debuggers (e.g. XDebug).

Unfortunately, there is no official and up-to-date reference on how to write PHP extensions. However, see this answer for several resources.

1016 questions
6
votes
2 answers

When to free memory in a PHP extension?

I'd like to create and return an array of arrays in a PHP extension. From what I understand, I should allocate the space for the array elements using emalloc(), but what I don't understand is when it is appropriate to free it. I have a PHP function…
rid
  • 61,078
  • 31
  • 152
  • 193
5
votes
6 answers

Using C/C++ code in PHP without writing an extension

I read it's possible to use C/C++ code in PHP by writing an extension. Is there a simpler way, like wrapping magic or things like that (I must say, I heard the word, but don't know much about what a wrapper is).
sameold
  • 18,400
  • 21
  • 63
  • 87
5
votes
2 answers

Adding imagemagick into my php 7.4 docker raised error

I need to add imagemagick into my php 7.4 docker, so in file Dockerfile.yml I added : FROM php:7.4.1-apache RUN apt-get update && \ apt-get install -y \ python \ libfreetype6-dev \ libwebp-dev \ …
Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
5
votes
3 answers

Problems Compiling PHP with SSH2 pecl extension for Windows

First, I am not a programmer. I am a Network Admin who has been asked to compile PHP for our web designer with SSH2 enabled. I have been following this walk-through to compile PHP for…
pat_micro
  • 51
  • 1
  • 2
5
votes
3 answers

Writing PHP extensions using Delphi 2010 and php4Delphi

Firstly this is about php4Delphi not RadPHP (formerly Delphi For PHP). Using Delphi 2010 PHP 5.3.6 (VC9, NTS) php4Delphi 7.2 (compiled with VC9 directive) Windows Server 2008 R2 IIS 7 When trying to run the php4Delphi delphi_math.dll example…
LachlanG
  • 4,047
  • 1
  • 23
  • 35
5
votes
0 answers

Can I develop a PDO extension with c++?

Can I write a PDO extension with c++ instead of c?(Windows10, PHP7.2) This is the contents(according to official docs) that a pdo ext should cover: config.m4 # unix build script config.w32 # win32 build script …
Deric Lee
  • 81
  • 3
5
votes
2 answers

wrap_newBundle not available SWIG & webpay

I want to setup webpay on my local Installed SWIG Added webpay extension to php.ini Then I tried to execute the test.php it shows the following error: --------error while opening file [libwebpayclient.so]--------

Starting webpay…

Ayyappadhas
  • 330
  • 1
  • 2
  • 9
5
votes
1 answer

Every time I'm trying to install the php-mysqli extension I'm getting error like "E: Package 'php-mysqli' has no installation candidate"

suvo@Suvodip-Lenovo ~ $ sudo apt install php-mysqli [sudo] password for suvo: Reading package lists... Done`enter code here` Building dependency tree Reading state information... Done Package php-mysqli is a virtual package provided…
Suvodip Mondal
  • 93
  • 1
  • 1
  • 6
5
votes
1 answer

PHP on method/function call event

Is there a way to catch method/function calls and return event with php like the xdebug trace? I tried using the register_tick_function, but i'm not pretty sure this is the good approach. I also tried to do my own php extension (using Zephir) but…
d3cima
  • 729
  • 1
  • 10
  • 31
5
votes
3 answers

WAMPSERVER php_memcache extension

I have a copy of php_memcache.dll (from php_memcache-2.2.6-5.3-nts-vc9-x86.zip) which I have placed in my C:\wamp\bin\php\php5.3.5\ext folder. In WAMP I can see php_memcache in my extensions list, however whenever I start the extension I get the…
fire
  • 21,383
  • 17
  • 79
  • 114
5
votes
1 answer

How to capture output from PHP extension when using PHP-FPM

I have a custom C extension loaded in my PHP and inside the extension there's a function does something like this void a() { printf("abc"); } I can call a() with no problem in CLI mode (command-line) and got the output abc as expected. But when…
Hammer
  • 1,514
  • 2
  • 14
  • 22
5
votes
1 answer

Install SPL_Types on PHP 7.1 compiled from source

I am trying to install SPL_Types extension in my PHP 7.1.8 compiled from source. I have tried with sudo pecl install SPL_Types and compiling the extension from source, but I get the following…
Vinicius Dias
  • 664
  • 3
  • 15
5
votes
1 answer

How does ArrayAccess work?

I've been reading about the commonly used interfaces of PHP from the SPL, such as Iterator, Countable, and ArrayAccess. However, I don't understand exactly how they work. Do their implementations modify the core functionality of PHP, for example…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
5
votes
2 answers

PHP Extension with C++

I recently started looking at writing PHP extensions and I read through this article, which describes a starting point for building an extension using C++. As I've started to customize, I've run into a hitch trying to split some of the functionality…
Nycto
  • 1,670
  • 2
  • 14
  • 18
5
votes
2 answers

modifying php-imap extension to allow oauth authentication

My php application logs into to Gmail via oauth provided access keys and fetch headers for all messages in inbox. The php-imap extension allows only for login/password based authentication. I want to modify the extension so that it support oauth…
Nands
  • 1,541
  • 2
  • 20
  • 33