3

I am trying to use WordPress XML-RPC. I found that by default XMLRPC will be enabled in my version of WordPress (3.9.1). But when I am trying to run the below PHP code, the following error is being displayed:

Fatal error: Call to undefined function xmlrpc_encode_request() in /Applications/XAMPP/xamppfiles/htdocs/easyblog/test/hellotest.php on line 6

Here is my PHP code.

<?PHP
//XML RPC Test
define('RPC_URL', 'http://localhost/wordpress/xmlrpc.php');
function sendRequest($methodName, $parameters)
{
    $request = xmlrpc_encode_request($methodName, $parameters);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, RPC_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    $results = xml_decode($results);
    curl_close($ch);
    return $results;
}

$parameters = array();
$response = sendRequest('demo.sayHello', $parameters);?>

Server Details:

I am using XAMPP server with PHP 5.5.11 on Mac OS X.

When I Googled this error I found that we need to enable XML-RPC in XAMPP php configuration file. So in XAMPP php.ini file I have uncommented extension=php_xmlrpc.dll and restarted the server and checked. But again I am getting the same error.

Marin Atanasov
  • 3,266
  • 3
  • 35
  • 39
  • Can you confirm php_xmlrpc.dll isn't enabled by viewing phpinfo()? – Luke Peterson Jun 29 '14 at 05:19
  • how can i check whether it is enabled or not? When i am running phpinfo() on two values regarding xmlrpc are displayed xmlrpc_error_number and xmlrpc_errors. – Upendra Siripurapu Jun 29 '14 at 05:26
  • I think it was not enabled. I used var_dump(get_loaded_extensions()), i didn't found xmlrpc. – Upendra Siripurapu Jun 29 '14 at 05:45
  • Can you confirm with phpinfo() that you're editing the right php.ini file? It will be at the top. – Luke Peterson Jun 30 '14 at 05:38
  • You're not using a Windows server, so loading a .dll won't do you any good. You might get lucky and get it working changing .dll to .so and restarting Apache. Otherwise I don't use XAMPP so I can't comment on enabling beyond that. – Arielle Lewis Oct 21 '14 at 19:03

1 Answers1

1

This is probably because you haven't installed the xmlrpc on your server. You can check the library doing the follow steps:

1) Create a new php document with this content. For example, info.php.

<?php
phpinfo();
?>

2) Open your browser and load the previous created page: http://YOUR-DOMAIN/info.php

3) Search "xmlrpc" section.

screenchot of info.php

4) On this point can happen 2 things:

4.1) If you have installed xmlrpc library, probably you have an error on your wordpress install or check point 5

4.2) If you HAVEN'T installed xmlrpc library on your server, you must to install. On ubuntu, you can install xmlrpc library writting sudo apt-get install curl libcurl3 libcurl3-dev php5-xmlrpc php5-curl on your terminal

5) Finally, check if your file php.ini has the extension enabled. Find the follow line ;extension=php_xmlrpc.so and remove de ";". Be carefull at this point: windows server has .dll extensions, UNIX servers (Mac OS X or Linux) has .so extensions.