Can I run PHP scripts from the command line, but not through the browser?

angryTom
Release: 2023-04-07 16:10:01
forward
2104 people have browsed it

Tonight when I was using the YAF framework, I encountered a problem: I can run the entry file of the YAF framework under the command line, but I can't run it through the browser?

This problem has troubled me all night. Fortunately, a group friend slowly helped me analyze it. Thank you very much!

The reason is: My FPM does not use yaf.so, but the CLI uses yaf.so.

So why does this happen? Because the command line and PHP-FPM are two different SAPIs, they can load php.ini files in different paths.

And through: php php file name

This method is to use the CLI SAPI.

Pass: http://localhost/index.php

This method uses the FPMSAPI.

So how do we check which extensions have been added in CLI mode? Use:

php -m
Copy after login

and use the following function in the PHP script:

<?php
phpinfo();
Copy after login

to see which extensions have been added to PHP-FPM.


The main reason why I put the error is that I always thought that CLI and FPM must share the same php.ini file. In fact, this is not necessarily the case. This can be specified when compiling the PHP source code.

emmm, I hope it can help everyone.

The foundation is really important...

happy ending...

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of Can I run PHP scripts from the command line, but not through the browser?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:huanghantao.github.io
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template