Home  >  Article  >  Backend Development  >  How to determine whether an extension is enabled in PHP

How to determine whether an extension is enabled in PHP

不言
不言Original
2018-04-13 10:24:502764browse

The content of this article is to share with you how PHP determines whether an extension is enabled. It has a certain reference value. Friends in need can refer to it

The development of PHP to this day has been very comprehensive and many All functions are included. However, many functions are installed in the form of extensions. The editor speculates that perhaps for efficiency, users can install them selectively.

The same function may be operated in several ways. For example, there are three ways to obtain interface data, namely curl library, fopen and file_get_contents. Among them, curl has relatively good scope and efficiency. But curl must be added via extension. So when we develop, we may consider this. When the curl extension is turned on, we use curl. When it is not turned on, we use the other two methods. So how to judge whether it is turned on? Let's take curl as an example:

Method 1:

if (get_extension_funcs('curl')); // 这种方式其实是不全面的

The function of this function is to return all functions of related extensions. If not installed, returns false. There seems to be no problem, but this method is inaccurate because some extensions do not have functions themselves, and even if they are installed, there will be no return value.

Method 2:

if (in_array('redis', get_loaded_extensions())); // get_loaded_extensions(),返回所有已安装的扩展,格式为一维数组

The above method is feasible and foolproof, but it is not the most concise.

<br/>

Method three:

if (extension_loaded(&#39;curl&#39;)) ;// 该方法最为简练,也最为科学




The above is the detailed content of How to determine whether an extension is enabled in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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