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
11
votes
1 answer

How do I compile an extension for PHP 5.3 for windows as a DLL?

I'm currently rewriting a PHP Extension that was originally written for PHP 4.2.2. My issue is having the build/compile process generate a .dll instead of compiling the extension into the PHP core. The environment is windows server 2003. I'm…
Ben Reisner
  • 662
  • 6
  • 16
10
votes
2 answers

How to install mcrypt on Docker

I have a Docker Container with Phalcon3 and php 7. I am trying to install the php extension Mcrypt without luck. If I do ssh to the container, and execute: apt-get update apt-get install php7.0-mcrypt I get the following: E: Unable to locate…
subharb
  • 3,374
  • 8
  • 41
  • 72
10
votes
1 answer

How to build SQL Relay for PDO from source on windows?

I am trying to integrate SQL Relay with PHP PDO on Windows (WAMP). I have installed and compiled Rudiments and SQL Relay on Windows through Visual Studio Developer Command Prompt following the instructions given on the Rudiments and SQL Relay…
Divakar Gujjala
  • 803
  • 8
  • 24
10
votes
2 answers

Can I put PHP extension classes, functions, etc. in a namespace?

I am writing a PHP extension in C, and I would like to put the classes, functions, and variables I am creating in a namespace. I have not been able to find anything in the extension documentation regarding namespaces. To be clear, I want the…
murgatroid99
  • 19,007
  • 10
  • 60
  • 95
10
votes
2 answers

XML Extension not found

I have centos 6.5 server and when I try to install php extension using pecl I get the following error: XML Extension not found All the documentations say that this extension is included by default... Why this error still exists?
King Julien
  • 10,981
  • 24
  • 94
  • 132
9
votes
0 answers

PHP Zend Engine Extension static method call

I am writing a PHP extension. From the C code I try to invoke a static method in PHP code. The PHP-method looks like this: The call in C looks like this: if(…
9
votes
2 answers

PHP Sql Server PDOException:could not find driver

My server is a Windows 2008 server. PHP Version 7.2.7 is installed and running. Sql Server 11 (64 bit) is installed and is working (there is a couple asp.net apps running and already using that database) I downloaded the PHP Sql Server Drivers from…
Soren
  • 797
  • 5
  • 15
  • 32
9
votes
1 answer

Installing mailparse php7 mbstring error

I'm currently working to put our project under php7. When trying to compile the mailparse extension or use pecl to install it, I get this error: #error The mailparse extension requires the mbstring extension! I did install the php7.0-mbstring and…
9
votes
1 answer

Resource garbage collected too early

I've created a PHP extension with SWIG and everything works fine, but I'm observing some strange garbage collection behavior when chaining method calls. For example, this works: $results = $response->results(); $row =…
Ed Mazur
  • 3,042
  • 3
  • 21
  • 21
9
votes
2 answers

What macros are available for php config.m4 files?

When writing a PHP extension, this documentation page indicates that a config.m4 file should be provided for autoconf to use. It gives a couple of examples of such files, but the documentation is incomplete. For example, the example file uses the…
murgatroid99
  • 19,007
  • 10
  • 60
  • 95
9
votes
4 answers

pgsql.so is not loaded in PHP

I've been tasked to create a PHP app which accesses an existing PostgreSQL database. This is my first time working with Postgre, not to mention the PHP has already been installed in the Linux box on which the app is supposed to run. I have no…
Obay
  • 3,135
  • 15
  • 55
  • 78
9
votes
1 answer

Writing a C++ extension for PHP 5.4, example code is obsolete

I am trying to write an extension for php5.4 which basically wraps a very simple class in CPP. This is for education purposes. I find the way to do it in php5.4 has changed from php5.3 Where do I find the documentation on how to do it? Or even…
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
9
votes
3 answers

Locate available (not loaded) PHP extensions

I need a way to find all the available PHP extensions whether they are loaded or not. I looked at How do I see the extensions loaded by PHP? but it only explains how to find loaded extensions. I want a way to find unloaded extensions also. Knowing…
maazza
  • 7,016
  • 15
  • 63
  • 96
8
votes
1 answer

PHP Warning: PHP Startup: Invalid library (maybe not a PHP library)

In the past i did create a shared library that now I would like to use it inside a php extension. Is it possible to do that? As I've seen in the config.m4 file PHP_NEW_EXTENSION() asks for the .cc . The problem is that i don't want to expose my…
sunset
  • 1,359
  • 5
  • 22
  • 35
8
votes
4 answers

Gmagick extension for php install -- how and where?

Downloaded php-pear and tried installing gmagick extension by following the steps given in link "http://www.gerd-riesselmann.net/development/how-install-imagick-and-gmagick-ubuntu" The pecl gave an error -- gmagick-1.0.9b1$ pecl install…