Table of Contents
Articles you may be interested in:
Home Backend Development PHP Tutorial Detailed explanation of hello word implementation method in PHP7 extension development

Detailed explanation of hello word implementation method in PHP7 extension development

Jun 30, 2018 pm 05:58 PM
php7 word Extended development

This article mainly introduces the implementation method of hello word in PHP7 extension development. It analyzes the specific steps and related operating techniques of PHP7 extension development in the form of examples. It involves the modification and compilation of the underlying source code of PHP. Friends in need can refer to the following

The example in this article describes the implementation method of hello word in PHP7 extension development. Share it with everyone for your reference, the details are as follows:

Here is based on PHP7, explaining how to create a PHP extension from scratch. This article mainly explains the basic steps to create an extension. In the example, we will implement the following functions:

<?php
echo say();
?>
Copy after login

Output content:

$ php ./test.php
$ hello word
Copy after login

Implement a say method in the extension. After calling the say method, the hello word is output.

Step one: Generate code

PHP provides us with a tool to generate basic code ext_skel. This tool is in the ./ext directory of the PHP source code.

$ cd php_src/ext/
$ ./ext_skel --extname=say
Copy after login

The value of the extname parameter is the extension name. After executing the ext_skel command, a directory with the same extension name will be generated in the current directory.

The second step is to modify the config.m4 configuration file

The function of config.m4 is to cooperate with the phpize tool to generate the configure file. The configure file is used for environment detection. Check whether the environment required for extension compilation and running is met. Now we start to modify the config.m4 file.

$ cd ./say
$ vim ./config.m4
Copy after login

After opening the config.m4 file, you will find this paragraph.

dnl If your extension references something external, use with:
dnl PHP_ARG_WITH(say, for say support,
dnl Make sure that the comment is aligned:
dnl [ --with-say       Include say support])
dnl Otherwise use enable:
dnl PHP_ARG_ENABLE(say, whether to enable say support,
dnl Make sure that the comment is aligned:
dnl [ --enable-say      Enable say support])
Copy after login

Among them, dnl is the comment symbol. The above code says that if the extension you write depends on other extensions or lib libraries, you need to remove the comments on the PHP_ARG_WITH related code. Otherwise, remove the comments from the PHP_ARG_ENABLE relevant code segment. The extensions we write do not need to rely on other extensions and lib libraries. Therefore, we remove the comment in front of PHP_ARG_ENABLE. The code after removing the comments is as follows:

dnl If your extension references something external, use with:
 dnl PHP_ARG_WITH(say, for say support,
 dnl Make sure that the comment is aligned:
 dnl [ --with-say       Include say support])
 dnl Otherwise use enable:
 PHP_ARG_ENABLE(say, whether to enable say support,
 Make sure that the comment is aligned:
 [ --enable-say      Enable say support])
Copy after login

The third step, code implementation

Modify the say.c file. Implement the say method.
FindPHP_FUNCTION(confirm_say_compiled), add the following code above it:

PHP_FUNCTION(say)
{
    zend_string *strg;
    strg = strpprintf(0, "hello word");
    RETURN_STR(strg);
}
Copy after login

FindPHP_FE(confirm_say_compiled, add the following code above:

PHP_FE(say, NULL)
Copy after login

The modified code is as follows:

const zend_function_entry say_functions[] = {
   PHP_FE(say, NULL)    /* For testing, remove later. */
   PHP_FE(confirm_say_compiled,  NULL)    /* For testing, remove later. */
   PHP_FE_END /* Must be the last line in say_functions[] */
 };
 /* }}} */
Copy after login

The fourth step, compile and install

The steps to compile the extension are as follows:

$ phpize
$ ./configure
$ make && make install
Copy after login

Modify the php.ini file and add the following code:

[say]
extension = say.so
Copy after login

Then execute the php -m command. In the output content, You will see the word say.

The fifth step is to call the test

Write a script yourself and call the say method. Look at the output Is it in line with expectations?

Articles you may be interested in:

Detailed explanation of the method of using lib library based on function in PHP extension development

The particularity of the volist tag in thinkphp in ajax operations

Detailed explanation of the volist tag in thinkphp

The above is the detailed content of Detailed explanation of hello word implementation method in PHP7 extension development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of how to display the ruler in Word and how to operate the ruler! Detailed explanation of how to display the ruler in Word and how to operate the ruler! Mar 20, 2024 am 10:46 AM

When we use Word, in order to edit the content more beautifully, we often use rulers. You should know that the rulers in Word include horizontal rulers and vertical rulers, which are used to display and adjust the document's page margins, paragraph indents, tabs, etc. So, how do you display the ruler in Word? Next, I will teach you how to set the ruler display. Students in need should quickly collect it! The steps are as follows: 1. First, we need to bring up the word ruler. The default word document does not display the word ruler. We only need to click the [View] button in word. 2. Then, we find the option of [Ruler] and check it. In this way, we can adjust the word ruler! Yes or no

How to add handwritten signature to word document How to add handwritten signature to word document Mar 20, 2024 pm 08:56 PM

Word documents are widely used due to their powerful functions. Not only can various formats be inserted into Word, such as pictures and tables, etc., but now for the integrity and authenticity of the files, many files require a manual signature at the end of the document. It sounds like this How to solve complex problems? Today I will teach you how to add a handwritten signature to a word document. Use a scanner, camera or mobile phone to scan or photograph the handwritten signature, and then use PS or other image editing software to perform necessary cropping on the image. 2. Select &quot;Insert - Picture - From File&quot; in the Word document where you want to insert the handwritten signature, and select the cropped handwritten signature. 3. Double-click the handwritten signature picture (or right-click the picture and select &quot;Set Picture Format&quot;), and the &quot;Set Picture Format&quot; pops up.

Do you know how to sum a Word table? Do you know how to sum a Word table? Mar 21, 2024 pm 01:10 PM

Sometimes, we often encounter counting problems in Word tables. Generally, when encountering such problems, most students will copy the Word table to Excel for calculation; some students will silently pick up the calculator. Calculate. Is there a quick way to calculate it? Of course there is, in fact the sum can also be calculated in Word. So, do you know how to do it? Today, let’s take a look together! Without further ado, friends in need should quickly collect it! Step details: 1. First, we open the Word software on the computer and open the document that needs to be processed. (As shown in the picture) 2. Next, we position the cursor on the cell where the summed value is located (as shown in the picture); then, we click [Menu Bar

How to underline in Word How to underline in Word Mar 20, 2024 pm 03:16 PM

As a very commonly used word processing software, Word is used in our life, study and work all the time. Of course, if you want to make good use of Word to edit text, you must lay a good foundation. So today I will take you to learn how to underline in Word. You can do it together with the editor. It is very simple. 1. First, we open the file we need to edit. Here we take the following figure as an example. 2. Use the mouse to select the text we need to edit. In the pop-up tab, we select the [U] icon. The operation is as shown in the figure: 3. Let’s take a look at the effect: 4. In fact, we can use a more convenient and faster The method is to use the key combination [ctrl] + [U] on the keyboard to add and follow your text.

How to switch tables horizontally and vertically in word How to switch tables horizontally and vertically in word Mar 20, 2024 am 09:31 AM

Word software is indispensable to us and needs to be used frequently. I have learned how to edit tables using Word software before. However, if I accidentally edit the table in the horizontal and vertical directions, and I don’t want to waste time re-creating it, is it possible to change the horizontal and vertical directions of the table? Woolen cloth? The answer is of course yes. Next, the editor will introduce to you in detail how to swap tables horizontally and vertically in Word. Let us learn together. First, we need to swap the rows and columns of the Word table below. To do this, we need to first select the table entirely, then right-click and select the copy function. Step 2: After selecting copy, we minimize word, then open an Excel table, right-click, select paste, and paste it into Exc

How to automatically sort word serial numbers How to automatically sort word serial numbers Mar 20, 2024 pm 09:20 PM

When there is a lot of content in word, there will be many chapters. It is impossible for us to write each chapter one by one. In fact, we can use the word serial number to automatically sort. The operation is simple and convenient. Friends who don’t know how to operate, come and learn it. Bar! 1. First, we open the document to be processed on the computer, as shown in the figure below: 2. After opening the document, select the text that needs to be automatically sorted. In this example, select [Chapter 1] and [Chapter 2] and hold down the Ctrl key. To select multiple areas, use the mouse to click the [Start] menu of Word after selection, as shown in the red circle in the figure below: 3. Click the small triangle symbol to the right of the number on the [Paragraph] toolbar, and click in the pop-up menu The serial number type that needs to be selected is as shown below with the red arrow pointing to it.

How to remove watermark in Word There are two ways to solve it How to remove watermark in Word There are two ways to solve it Mar 20, 2024 am 09:19 AM

Word software has been used in everyone’s daily work and life. When using Word, everyone will want to add a watermark to the Word document. However, after adding the watermark, many people want to remove the watermark from the Word document. Many people do not know how to remove it, which is a bit confusing. What should friends who are too familiar with operating Word do? Today I will explain to you how to remove watermarks in Word. First open a document with a watermark in a Word document. Then find the &quot;Insert&quot; menu in the toolbar and click the [Watermark] option. Finally, select the [Delete Watermark] option in the pop-up drop-down option. After the operation is completed, when we return to the document, we will find that the watermark in the previous document has been removed. I don’t know if you have noticed that, in fact, “watermark

How to insert automatic numbering or serial numbers into Word tables How to insert automatic numbering or serial numbers into Word tables Mar 20, 2024 am 09:30 AM

When we make tables, the first thing we think of is to use Excel software to make tables. But did you know that Word software is actually very convenient to make tables. Sometimes when we make tables in Word software, we need to enter serial numbers or numbers. , if you enter them one by one manually, it will be very troublesome. In fact, there is an operation in the word software that can automatically insert numbers or serial numbers. So let’s learn with the editor how to insert automatic numbering or serial numbers into Word tables. . 1. First create a Word document and insert a table. 2. Select the column or cell where you want to insert automatic serial numbers or numbers. 3. Click &quot;Start&quot; - &quot;Number&quot;. 4. Select one of the style numbers. 5.

See all articles