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

How can I install soap.so extension on debian with php5 and apache2?

I have a debian server with php5 in apache2 and I want to use soap extension. I install soap extension with # sudo apt-get install php-soap, I modify php.ini with extension=php_soap.so and I reset apache. But I check phpinfo and soap extension is…
majareta
  • 63
  • 2
  • 2
  • 6
4
votes
2 answers

How can I write a custom PHP extension which can modify the internals of the PHP interpreter?

Is it possible to write a PHP extension (UNIX, CGI SAPI) where I can: redefine the implementation of a PHP function (like with mail(): many PHP softwares uses the standard mail() function - I can't change that since customers want to use that,…
LGB
  • 728
  • 1
  • 9
  • 20
4
votes
1 answer

Using Hiphop for PHP extension development

Hiphop converts PHP into C++ code, did anyone used it for PHP extension development? I have found following link to write PHP extensions using C++ http://devzone.zend.com/article/4486-Wrapping-C-Classes-in-a-PHP-Extension I want to write some PHP…
SuVeRa
  • 2,784
  • 2
  • 20
  • 27
4
votes
1 answer

Problem serializing c++ class accessible through a php extension

I wrote a C++ library that exposes a number of classes. I also wrote a php extension using zend, as a wrapper over the c++ library. I have a problem properly serializing my objects, when, for example, I try to store them in $_SESSION. Here is an…
kounoupis
  • 41
  • 1
4
votes
1 answer

Gmp PHP extension - MAMP PRO

I've looked around several other questions like this one, guide like this or this but I still had no luck. Here's what i've done so far: Downloaded gmp with brew using brew install autoconf gmp Downloaded PHP (i'm using version 7.3.24) from…
Diego
  • 1,610
  • 1
  • 14
  • 26
4
votes
2 answers

How to install php-zip extention on scrutinizer-ci?

I tried to use scrutinizer on my repo but return: Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages. …
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
4
votes
0 answers

How do I check which PHP extensions my application needs to work?

I wrote a simple application in PHP. During the development I used XAMPP, and now I want to upload it to a "real" server. I do not want to install too many extensions on my server. How can I check which extensions my application needs?
Karcin
  • 41
  • 4
4
votes
2 answers

php gd lib is installed but not working

On the localhost the library is working fine, when the function is called on production,php throws a fatal errer. i checked the phpinfo() its there and it is enabled. I tired to see if there is anything that i can add on the php.ini but i couldn't…
zf.
  • 123
  • 1
  • 1
  • 10
4
votes
1 answer

How to enable php extension using `phpize`?

I tried these steps on different extensions but I don't know why that doesn't work. Shouldn't I see a change in phpinfo() output after that? The steps: Decompress the php source code and change directory to ext/ext_name phpize configure make move…
Reem
  • 1,439
  • 2
  • 18
  • 21
4
votes
1 answer

Can ext-json be disabled?

Can the json extension be disabled in PHP? The doc says that: As of PHP 5.2.0, the JSON extension is bundled and compiled into PHP by default. But some people in the comments say that the json extension is sometimes provided as a separate…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
4
votes
0 answers

Install PHP ZIP extension in MAMP Pro

I am trying to Install PHP ZIP extension in MAMP Pro. I followed many tutorials, and official one: MAMP Documentation But didn't get the job done at all. Here's what I get when installing from terminal using sudo pecl install zip: downloading…
CairoCoder
  • 3,091
  • 11
  • 46
  • 68
4
votes
0 answers

php7.4 extension amqp installed but not loaded

I have installed latest version 1.9.4 amqp with php7.4 its installed successfully. When I am checking it its shown in the phpinfo(); **when I am checking through the following command ** /etc/apt$ php --ini PHP Warning: Module 'amqp' already…
MayUr
  • 67
  • 1
  • 13
4
votes
0 answers

How to make the php extension(.so) file portable with dependent libraries?

I need to make an php extension(.so) file which can be made portable. The created library works fine on one of my machines, but, when I send it to other machine, it does not load properly as a dependency of cJSON is missing on the target machine. I…
ankit jain
  • 350
  • 2
  • 12
4
votes
1 answer

dockerfile not updating container

I'm working with an app using docker (i'm not super familiar) and I need to add 2 new PHP extensions. I have changed the Dockerfile on an existing image as follows: FROM php:7.2-fpm RUN apt-get update RUN apt-get install -y git unzip RUN php -r…
simonw16
  • 960
  • 9
  • 25
4
votes
1 answer

Apache isn't loading PHP extensions

I installed(manually) Apache and PHP. I activated the curl extension from php.ini and It's working fine in PHP-CLI, but when I access PHP through browser with the help of Apache, curl(and any other) extension giving me errors that…
Inam Ul Huq
  • 732
  • 7
  • 8