PHP xml-rpc problem using ripcord library

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
AhmedHaroon
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Apr 06, 2021 10:38 pm

Wed Apr 07, 2021 12:46 am

hi all, please if this is not appropriate place to post this question, kindly move it to and inform to have track.

I want to use Odoo (previsouly OpenERP) webservices using PHP as the examples on Odoo documentation (Odoo External API), link is here: https://www.odoo.com/documentation/14.0 ... /odoo.html

I have tried python examples on above page which works fine... even from another machine's same vm (both vm's are Ubuntu 18.04 Desktop, running Odoo 14) I have not any idea of using/writing code in PHP, on my Windows host machine, I have downloaded XAMPP portable, enable xmlrpc in php.ini, installed ripcord library through composer, (as "ripcord" used in PHP examples in above official guide) started XAMPP controller + Apache, created a .php file in d:\xampp\htdocs\mytest\test.php with code below:

Code: Select all

<?php

//url = my ubuntu vm ipv4 with odoo default port
$url = "http://192.168.18.71:8069"; 
$db = 'odb';
$username = 'odoouser@myhost.com';
$password = 'admin';

require_once('ripcord.php');
$common = Ripcord::client($url'/xmlrpc/2/common');
$ver = $common->version();
echo $ver;
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;
?>
run the page in Chrome, it says Warning: require_once(ripcord.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\test.php Fatal error: require_once(): Failed opening required 'ripcord.php' (include_path='\xampp\php\PEAR') in D:\xampp\htdocs\mytest\tests.php
Is there anything else i missed or have to configs/settings or should i have xmlrpc.php too? if yes, where it should be copied? please help as I am stuck. if any related info required, please ask for to have enough information to resolve the problem.
regards
simonbrahan
php-forum Super User
php-forum Super User
Posts: 154
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Wed Apr 07, 2021 2:27 am

PHP uses a user defined autoload function to find the code for classes as you instantiate them. If you're using composer, the autoload for your included packages is probably at "vendor/autoload.php". Change you require_once line as follows:

Code: Select all

require_once('vendor/autoload.php');
And let us know how that works.
AhmedHaroon
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Apr 06, 2021 10:38 pm

Wed Apr 07, 2021 2:45 am

thanks @simonbrahan for reply. i modified the code as per instruction but it is showing same error
Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\tests.php on line 10

Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='\xampp\php\PEAR') in D:\xampp\htdocs\mytest\tests.php on line 10
tests.php

Code: Select all

<?php

//url = my ubuntu vm ipv4 with odoo default port
$url = "http://192.168.18.71:8069";
$db = 'odb';
$username = 'odoouser@myhost.com';
$password = 'admin';

require_once('vendor/autoload.php');
$common = ripcord::client($url'/xmlrpc/2/common');
$ver = $common->version();
echo $ver;
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;
?>
simonbrahan
php-forum Super User
php-forum Super User
Posts: 154
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Thu Apr 08, 2021 12:55 am

Do you have a vendor folder in your codebase? Composer should have created one, and the path in your require_once command should point to it.
AhmedHaroon
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Apr 06, 2021 10:38 pm

Thu Apr 08, 2021 10:12 pm

simonbrahan wrote:
Thu Apr 08, 2021 12:55 am
Do you have a vendor folder in your codebase? Composer should have created one, and the path in your require_once command should point to it.
thanks for your passions to help me.

Do you have a vendor folder in your codebase?
sorry, i don't know what it here means "codebase", if its my project folder then no, i just have a tests.php file and nothing in my D:\xampp\htdocs\mytest\ folder

when searched for name vendor in my xampp (portable) folder, it shows me as below:
some folders:
D:\xampp\composer\vendor
D:\xampp\phpMyAdmin\js
D:\xampp\perl

some files like:
D:\xampp\phpMyAdmin\libraries\vendor_config.php
D:\xampp\phpMyAdmin\doc\html\vendors.html
D:\xampp\phpMyAdmin\doc\html\vendors.rst.txt
etc.

is it you meand that it needs to copy D:\xampp\composer\vendor folder in D:\xampp\htdocs\mytest folder?
or something else?

after copying "vendor" folder from composer to my project folder and put the same code as mentioned in your earlier post [ require_once('vendor\autoload.php') it is showing now
Fatal error: Uncaught Error: Class 'ripcord' not found in D:\xampp\htdocs\mytest\tests.php:11 Stack trace: #0 {main} thrown in D:\xampp\htdocs\mytest\tests.php on line 11
about path: is it should be require_once('D:\xampp\htdocs\mytest\vendor\darkaonline\ripcord\src\Ripcord\ripcord.php')?
or something else?
regards
AhmedHaroon
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Apr 06, 2021 10:38 pm

Fri Apr 09, 2021 12:06 am

@simonbrahan
thanks for your all efforts to help me :)
its done, i received response from Odoo database.
i cloned ripcord library from github using GitBash while I was in my project directory "mytest" with command below:
my php file:

Code: Select all

<?php

$url = "http://192.168.18.71:8069";  // my vm url -- note its http NOT https 
$db = 'odb';  // database name in Odoo -- Odoo uses PostgreSQL
$username = 'odoouser@myhost.com';  // Odoo user 
$password = 'admin';  // password for user 

require_once('ripcord\ripcord.php'); // ripcord library included here with path starts from project directory
$common = ripcord::client($url.'/xmlrpc/2/common'); 
$ver = $common->version();
$uid = $common->authenticate($db, $username, $password, array()); // authentication successful if uid contains a positive value
echo $uid;  // print uid value in browser 

?>
i am getting user id in chrome browser. now will go further to get data... actually CRUD operations.
thanks again.
regards

( now you can close this topic. i copy/pasted here the solution which can be beneficial for any one who want it )
Post Reply