Home  >  Article  >  Backend Development  >  Can I run PHP scripts from the command line, but not through the browser?

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

angryTom
angryTomforward
2019-10-15 10:41:582041browse

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

and use the following function in the PHP script:

<?php
phpinfo();

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!

Statement:
This article is reproduced at:huanghantao.github.io. If there is any infringement, please contact admin@php.cn delete