Determining if a PHP function is available
Sometimes you need to check whether a specific PHP function is enabled on your hosting account. On ruachost.com, you can do this using the built‑in function_exists() function.
Why Check Function Availability?
Section titled “Why Check Function Availability?”- Hosting environments may disable certain PHP functions for security reasons.
- Ensures your script won’t break if a function is unavailable.
- Helps you write portable code that works across different servers.
Using the function_exists() Function
Section titled “Using the function_exists() Function”The function_exists() function returns true if the specified function is available, and false if it is not.
Example: Checking for fsockopen()
Section titled “Example: Checking for fsockopen()”<?php$function_name = "fsockopen";
if (function_exists($function_name)) { echo "$function_name is enabled";} else { echo "$function_name is not enabled";}?>Steps:
Section titled “Steps:”- Save the file as
function.php. - Upload it to your
public_htmldirectory. - Visit
http://yourdomain.com/function.php. - The page will display whether the function is enabled.