What are the results of self-written PHP extensions running on command lines and browsers?

Source: Internet
Author: User
What are the results of self-written PHP extensions running on command lines and browsers? I used a PHP extension written in C ++. after compilation and installation, the problem arises. please let me know.

1. I wrote a test script ctp. php for testing.
 ";if(function_exists("helloWorld")){echo "exist\n";}else{echo "none exist\n";}echo helloWorld('baren')


2. run the following results on the browser and command line respectively:


3. my questions:
1) why cannot I print the value of the hellWorld () function in the browser?
2) How do I fix this error? do I need to change any configuration files?
3) too many solutions, such as permission change and environment variable change, cannot be found online. So my last question is, isn't it related to the development environment?

4. my development environment:
OS version: centos 7 x86_64
Php version: 5.4.43
Webserver: Apache/2.4.16 (Unix)

Can anyone who has experience in programming and deploying extensions help?

Thank you!


Reply to discussion (solution)

I only know that the configuration file used in php running cli mode is different from the configuration file used for executing web. you should add your extension to the configuration file running web.
The configuration file/usr/local/php/etc/php. ini is used on the web.
The cli should be/etc/php. ini.

Thank you for your answer, but your answer is wrong.
Your error is as follows:
1. the configuration files for CLI and WEB are the same. In addition, I only added my extension configuration file ctpextension during deployment. ini is placed in Scan this dir for additional. the default directory of ini files is/usr/local/php. d. When PHP loads the configuration file, it will automatically check this directory and put ctpextension. append the content in the ini file to php and ini.

2. you said, "the cli should be/etc/php. ini "I also found this file directory in my system, so I deleted this file and run the script on the command line to get the same result. Prove that your statement is incorrect.

About additional. ini files you can read here: http://php.net/manual/zh/function.php-ini-scanned-files.php

The command line loads php in real time, but the web is not. after modifying the php configuration, such as adding extensions, you need to restart the server to make it take effect.

The command line loads php in real time, but the web is not. after modifying the php configuration, such as adding extensions, you need to restart the server to make it take effect.


Thank you for reminding me that I will not make such a low-level mistake.

Let's stop guessing. I have asked a foreign developer to solve this problem.
In fact, this problem has nothing to do with the configuration. my configuration is correct, otherwise it will not show that my function already exists on the command line and browser side.

The cause of the problem is that the third-party libraries on which my PHP Extension Library depends have been changed, but I still read the documents of the old version without knowing it,

Therefore, the browser does not output results.

I just need to change std: cout in my C ++ file to Php: out.

Let's take a look at my long-awaited results.

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.