Use PHP to call C to expand the entire configuration process (great effort)

Source: Internet
Author: User

Today, I finally added the C extension to PhP and can call it. I will not talk about this nonsense.

1. You must install Apache and MySQL first.

Ii. install PHP

# Mkdir/usr/local/PhP5

#. /Configure -- prefix =/usr/local/PhP5 -- with-apxs2 =/usr/local/apache2/bin/apxs -- With-mysql =/usr/lib64/MySQL -- With-config- file-Path =/usr/local/PhP5

# Make
# Make install

3. Check whether PHP is successfully installed.
Create a file name in Apache htdocs: index. php
Write content <? Phpinfo ()?>
Save
Browse http: // localhost/index. php
The installation is successful.

4. Create your own c php Extension
Go to the ext directory of the PHP installation package
# Cd/usr/software/php5-3.2/EXT
#./Ext_skel -- extname = mysqlc Note: Here is the name of the extension library in the creation. After the creation, there will be a mysqlc directory under Ext.
# Cd mysqlc

5. Perform basic modification and encoding operations on the extended library
# Vi config. M4

Original
DNL php_arg_enable (mysqlc, whether to enable mysqlc support,
DNL make sure that the comment is aligned:
DNL [-- enable-mysqlc enable mysqlc support])

Modified
Php_arg_enable (mysqlc, whether to enable mysqlc support,
Make sure that the comment is aligned:
[-- Enable-mysqlc enable mysqlc support])

# Vi mysqlc. c

Append an object to the php_function (confirm_mysqlc_compiled) Function

Php_function (mysqlc ){
Zend_printf ("helloword C !! ");
}

Before Modification
Const zend_function_entry mysqlc_functions [] = {
Php_fe (confirm_mysqlc_compiled, null)/* for testing, remove later .*/
{Null, null, null}/* must be the last line in mysqlc_functions [] */
};

After modification
Const zend_function_entry mysqlc_functions [] = {
Php_fe (confirm_mysqlc_compiled, null)/* for testing, remove later .*/
Php_fe (mysqlc, null)
{Null, null, null}/* must be the last line in mysqlc_functions [] */
};

# Vi php_mysqlc.h
Append an object to php_function (confirm_mysqlc_compiled );

Php_function (mysqlc );

At this point, your extension library is basically finished, and the generation and installation of the extension library will begin.

5. generate an extension Library
Current Directory in/usr/software/php5-3.2/EXT/mysqlc

#/Usr/local/PhP5/bin/phpize

#./Configure -- With-PHP-Config =/usr/local/PhP5/bin/PHP-config

# Make

# Make install

After the script is executed, the file/usr/local/PhP5/lib/PHP/extensions/no-debug-non-ZTS-version/mysqlc. So will be displayed.

Copy the mysqlc. So file to the modules under Apache.

4. Configure PHP. ini

Then go to/usr/local/PhP5 to check whether PHP. ini exists,

If no, copy the php. ini-production in the installation package to PhP. ini.

Go to PhP. ini settings
1. short_open_tag = on
2. extension_dir = "/usr/local/apache2/modules /"
3. append an extension = mysqlc. So
Save PHP. ini and restart Apache

OK. The extension library can be used.

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.