Php extension, a helloworld implementation

Source: Internet
Author: User

Php extension, a helloworld implementation


Php-v
PHP 5.5.9-1ubuntu4. 7 (cli) (built: Mar 16 2015 20:47:39)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
With Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
With Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

Configuration reference: http://blog.csdn.net/niujiaming0819/article/details/8543028
This article also uses the steps described in the document as the local implementation process

Step 1.Download the php source code package. You can download the php official website. php5.6.8 is used this time.
Step 2. decompress the compressed package, enter the decompressed package (mysoft $ cd php-5.6.8/), with the ls command to view the file directory in the source package, enter the ext folder (cd ext)



Step 3. Establish an extended development framework ./Ext_skel -- extname = helloworld

Execute the preceding command to establish an extended development framework. You will find that there is an additional folder named helloworld under the ext folder, and the command line also outputs some text,

You will be prompted for the general steps for generating the extension.

 






Step 4.Go to the root directory of the php source code and edit the vim ext/helloworld/config. m4 file.

Several lines of comment in this file will be roughly between lines 16-19. The specific version may be different and save the file (: wq)

 

Step 5.Run the command./buildconf -- force in the root directory of the php source code.

 

 

Step 6.Compile the php program in the root directory of the php source code. Note that the command is./configure -- with-helloworld.

The last error is not handled.

Step 7.Go to our extension directory helloworld and execute the command phpize (install phpize via sudo apt-get install php5-dev). At this point your extension directory will generate a lot of files that can be used for post-compilation.

Step 8.Compile our extension./configure -- with-php-config =/usr/bin/php-config in the helloworld directory (Use php-config in your environment) -- enable-helloworld

You can run a command to find the location of your php-config file (find/-name php-config). My address is/usr/bin/php-config.

 

Step 9. Go to the extended helloworld directory, edit the file php_helloworld.h, and add the function PHP_FUNCTION (helloworldTest) in the last line );

You can change helloworldTest to your preferred name, and then save and exit.

 

Step 10. Use vim to open helloword. c, implement our function in helloworld. c, add the helloworldTest function to helloworld_functions [], save and exit

 

 

Step 11.Execute the make command to compile the extension, and I am still running smoothly. If an error occurs, check whether there are any errors in the previous step. The errors I made during the first step are generally due to errors in the previous step.

 

Step12. copy the compiled helloworld. so file to the php extension directory on your local machine.

You can use php-r phpinfo (); | grep extension_dir to view the extension path of php on the local machine.

Step 13. Configure php. ini to enable helloworld. so Extension

View the location of php. ini (php-r phpinfo (); | grep php. ini)

Vim open the php. ini file sudo vim/etc/php5/cli/php. ini

Add extension (extension = helloworld. so) at the end of the file)

Test with php-r phpinfo (); | grep helloworld

Step 14. Test the extension (php-r echo helloworldTest ();)

 

 

In this process, I tried according to the original author's steps, and an error occurred.

Segmentation fault "(core dumped)

After debugging, the original author is in helloworld. when the c file is added to helloworld_functions [], PHP_FE_END is replaced with {null, null, null}, and PHP_FE_END is commented out for PHP_FE_END even if no error occurs during self-compilation. After the modification, recompile and copy.

 

 

 

 

 

 





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.