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
26
votes
4 answers

WARNING: Module ini file doesn't exist under /etc/php/7.0/mods-available

I have uninstalled php7 and all its modules from ubuntu, and when I try to reinstall the modules, I get the following error for each php module, and although the module is installed, because of this error, it is not activated and I cannot use…
TheDevWay
  • 1,363
  • 1
  • 16
  • 45
25
votes
1 answer

Get PHP Opcodes Dynamically at Runtime

I want to build a PHP extension that can dynamically inspect every opcode generated from a PHP file and do some checking on that. I came across several websites and found out a couple of functions like zend_set_user_opcode_handler, but I fail to…
ebudi
  • 287
  • 2
  • 3
25
votes
3 answers

Check dynamically loaded PHP extensions from command line

I was checking the PHP manual to understand the different types of PHP extensions (PHP modules). There are Zend modules (mainly for PHP gurus), built-in modules and external modules. Is there a way to tell from command line whether a PHP module has…
rodrunner
  • 1,860
  • 4
  • 23
  • 34
22
votes
2 answers

Interchanging data with zend (multidimensional arrays)

I'm embeding PHP in my app (writen in Delphi 2010), using PHP4Delphi component to interface with php5ts.dll. I guess my program acts as extension for the PHP (sapi module?) as it registers some functions and constants which can be used in PHP…
ain
  • 22,394
  • 3
  • 54
  • 74
21
votes
3 answers

Install PHP Extension for PHP 5.6 on OSX with deprecated homebrew/php

today I've update Brew and now I can't install the php56-extensions. On my Mac is installed "php56" and today I had need to install, "php56-redis", but when I had try to install this extension, Brew returned the following error message. $ brew…
Giampaolo
  • 333
  • 1
  • 2
  • 8
21
votes
2 answers

Run `docker-php-ext-install` FROM container other than php

I have a problem with Docker (docker-compose). I want to install some PHP extensions using docker-compose.yml, but I am unable to do this, because my .yml has FROM ubuntu and not FROM php. Is there any way I can achieve or access the…
Albert221
  • 5,223
  • 5
  • 25
  • 41
20
votes
3 answers

How to install gmp extension for php 7.2 using MAMP on OSX

How to install gmp extension for php 7.2.1 using MAMP on OSX? I'm trying to encrypt a token with php and this library(lcobucci/jwt) using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm.…
Lloyd Keijzer
  • 1,229
  • 1
  • 12
  • 22
20
votes
2 answers

How to start writing a PHP5 extension in C++

I'm writing a PHP5 extension, and while I could write it in C, it would be easier to use C++ and take advantage of the STL and Boost. Trouble is, the tutorials I've seen only deal with C, and I'm looking for a basic example which uses C++ Here's…
Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
20
votes
4 answers

PHP Startup: Unable to load dynamic library `curl.so` Ubuntu

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/curl.so' - /usr/lib/php/20131226/curl.so: undefined symbol: zend_unset_property in Unknown on line 0 I am using Ubuntu 14.04 LTS and PHP v5.6 There are other…
HADI
  • 2,829
  • 1
  • 26
  • 26
20
votes
1 answer

Startup: Unable to load dynamic library '/usr/lib/php/modules/module.so'

When I run the command php -v this error comes up PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/module.so' - /usr/lib/php/modules/module.so: cannot open shared object file: No such file or directory in Unknown on…
SimpleSpawn
  • 831
  • 1
  • 7
  • 18
19
votes
1 answer

PHP. Extension. Call existing PHP function

So I decided to write an extension for php. Everything seems to be fine except I'm stuck on a tiny problem. I have php-5.4.9 source codes. There is file ext/standard/mail.c with awesome function PHPAPI int php_mail(char *to, char *subject, char…
nkamm
  • 627
  • 5
  • 14
16
votes
1 answer

how to write PHP module in C

how can i write my own module in C ? is it possible ?
Sourav
  • 17,065
  • 35
  • 101
  • 159
15
votes
3 answers

Returning "Native" PHP Objects from an Extension

I'm dabbling with creating a PHP extension for a personal project. Beyond what's linked in the above article I have no knowledge of the zend_engine, and my C skills are 10 years out of date, and were only ever academic. All of which is to say "If…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
15
votes
6 answers

phpredis extension doesn't work, unable to load 'redis.so'

I installed nginx, php, php-fpm, php-pecl-redis by yum. All of them work but the last one. When I run /usr/sbin/php-fpm, I got this: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/redis.so' -…
pearzl
  • 323
  • 1
  • 2
  • 10
15
votes
5 answers

How can I install PHP extension libsodium in Wampserver?

I am trying to install the Libsodium PHP extension using PECL, but I have no idea how to get the dll files needed. I want to use it with Wampserver on Windows 7 (64-bit). Can any one help me?
LearningToCode
  • 631
  • 1
  • 12
  • 23
1
2
3
67 68