Home  >  Article  >  Backend Development  >  Solution to PHP Fatal error: Call to undefined function fsockopen()

Solution to PHP Fatal error: Call to undefined function fsockopen()

WBOY
WBOYOriginal
2023-06-22 15:24:281439browse

If you encounter the error message "PHP Fatal error: Call to undefined function fsockopen()" when using PHP, it means that the fsockopen function is not enabled in your PHP environment. In this article, we will solve this problem through the following steps:

  1. Check whether the fsockopen function is enabled;
  2. If it is not enabled, modify the php.ini configuration file;
  3. Restart the Apache server;
  4. Test whether the problem is solved.

Let’s introduce the above steps in detail.

  1. Check whether the fsockopen function is enabled

First, you need to determine whether the fsockopen function is enabled in your PHP environment. You can check whether the fsockopen function is enabled in your PHP environment by creating a phpinfo page. The method is as follows:

1) Create a new file in a text editor and name it phpinfo.php (note the suffix The name must be .php);
2) Enter the following content in the file:

<?php
phpinfo();
?>

3) Save the file and upload it to the web root directory of your server;
4) Enter "http://your domain name/phpinfo.php" in the browser to access the page.

In this page, you can search for the "fsockopen" keyword and find the "Registered PHP Streams" or "PHP Environment" section, where there should be a "fsockopen" listed. If it is not listed, it means that the fsockopen function is not enabled in your PHP environment and you need to proceed to the next step.

  1. If it is not enabled, modify the php.ini configuration file

Modify the contents of the php.ini configuration file to include the fsockopen function. The specific operations are as follows:

1) Use SSH to log in to the server;
2) Enter the following command to find the location of the php.ini file:

php -i|grep php.ini

This will output the details of the php.ini file Path;
3) Open the php.ini file with an editor, find the "disable_functions" line in the php.ini file, comment it out (add # before the semicolon), and then add "fsockopen" to the line ", for example:

disable_functions = #disable_functions = show_source, system, shell_exec, passthru, exec, phpinfo, fsockopen

Please note that if there is no "disable_functions" line in your php.ini file, you need to add it manually.

4) Save and close the php.ini file.

  1. Restart the Apache server

After completing the modification of the php.ini file, you need to restart the Apache server to make it take effect. The specific operations are as follows:

1) Use the following instructions to restart the Apache server:

service httpd restart

2) Wait a few seconds until the Apache server restart is completed.

  1. Test whether the problem is solved

While testing, you can try running the code that triggered the "fsockopen" function call again. If the problem has been resolved, your code should execute successfully.

Summary

In this article, we explain in detail how to solve the problem of "PHP Fatal error: Call to undefined function fsockopen()" through four steps. If you encounter this problem, you can solve it by following the steps provided in this article. Finally, if you encounter other problems or have other questions when solving the problem, you can leave a message in the comment area.

The above is the detailed content of Solution to PHP Fatal error: Call to undefined function fsockopen(). 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