- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
API: PHP Try to connect via RPC
- sarah_w
- Topic Author
- Offline
- New Member
Less
More
7 years 1 month ago #148885
by sarah_w
API: PHP Try to connect via RPC was created by sarah_w
Hello
I try to connect via RPC to LimeSurvey and followed the PHP example from here: manual.limesurvey.org/RemoteControl_2_API#PHP_Example
include_once 'vendor/autoload.php';
define( 'LS_BASEURL', 'myurl'); // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myuser' );
define( 'LS_PASSWORD', 'mypassword');
// the survey to process
$survey_id=12345678;
// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL );
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
// release the session key
//$myJSONRPCClient->release_session_key( $sessionKey );
When executing the script, the following error occurs:
"Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to MYURL' in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php:155 Stack trace: #0 E:\project\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->__call('get_session_key', Array) #1 E:\msf\benteler\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->get_session_key('myuser', 'mypassword') #2 {main} thrown in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php on line 155"
The Username and password and the URL are correct. Also I can connect to the API with "R" (the statistic programming language) and with my login data. Just in PHP this error occurs and so far I found nothing that helps me out.
Any help is really appreciated.
I try to connect via RPC to LimeSurvey and followed the PHP example from here: manual.limesurvey.org/RemoteControl_2_API#PHP_Example
include_once 'vendor/autoload.php';
define( 'LS_BASEURL', 'myurl'); // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myuser' );
define( 'LS_PASSWORD', 'mypassword');
// the survey to process
$survey_id=12345678;
// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL );
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
// release the session key
//$myJSONRPCClient->release_session_key( $sessionKey );
When executing the script, the following error occurs:
"Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to MYURL' in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php:155 Stack trace: #0 E:\project\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->__call('get_session_key', Array) #1 E:\msf\benteler\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->get_session_key('myuser', 'mypassword') #2 {main} thrown in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php on line 155"
The Username and password and the URL are correct. Also I can connect to the API with "R" (the statistic programming language) and with my login data. Just in PHP this error occurs and so far I found nothing that helps me out.
Any help is really appreciated.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
7 years 1 month ago #148905
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic API: PHP Try to connect via RPC
myurl is an example , you must set the real url , seems the issue is here. Or your server broke web access (firewall issue).
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- sarah_w
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #148924
by sarah_w
Replied by sarah_w on topic API: PHP Try to connect via RPC
Hey,
thanks for your answer. I set an real URL, just commented all sensitve data out and replaced it with dummy data.
I tested yesterday and the issue was that I tried to connect to my URL via https: under Windows. After some time of searching i found out that curl under Windows needs to set SSL_VERIFYPEER set to FALSE.
So for my locale maschine I had to set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
inside class "JsonRPCClient". Afterwards it works well.
thanks for your answer. I set an real URL, just commented all sensitve data out and replaced it with dummy data.
I tested yesterday and the issue was that I tried to connect to my URL via https: under Windows. After some time of searching i found out that curl under Windows needs to set SSL_VERIFYPEER set to FALSE.
So for my locale maschine I had to set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
inside class "JsonRPCClient". Afterwards it works well.
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
7 years 1 month ago #148925
by jelo
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic API: PHP Try to connect via RPC
Which is depending on how and what certs you installed. I don't think you have to disable SSL_VERIFYPEER always when Windows is involved. You would end up with a potential unsecure connection. curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.htmlsarah_w wrote: I tested yesterday and the issue was that I tried to connect to my URL via https: under Windows. After some time of searching i found out that curl under Windows needs to set SSL_VERIFYPEER set to FALSE.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
7 years 1 month ago #148929
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic API: PHP Try to connect via RPC
@jelo : yes, but if you use self-signed certificate : you NEED SSL_VERIFYPEER to false.
Else @sarah_w : if you have some times (or some people with time) : letsencrypt.org/ can help you to have a valid certificate (and it's better to verify peer). BTW : not limesurvey related.
Denis
PS : maybe we need to update pour manual about this 'issue'
Else @sarah_w : if you have some times (or some people with time) : letsencrypt.org/ can help you to have a valid certificate (and it's better to verify peer). BTW : not limesurvey related.
Denis
PS : maybe we need to update pour manual about this 'issue'
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- sarah_w
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #148930
by sarah_w
Replied by sarah_w on topic API: PHP Try to connect via RPC
@jelo: It's only my development laptop with its Windows. Just needed to test my code, therefore I think it's okay to set SSL_VERIFYPEER to false. On the live system it didn't adapt the code.
@DenisChenu: Sorry just turned out now that it was not LimeSurvey related. But maybe someone has the same problem and this can help.
@DenisChenu: Sorry just turned out now that it was not LimeSurvey related. But maybe someone has the same problem and this can help.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
7 years 1 month ago #148932
by DenisChenu
If you can found time to add a 'warning : if you don't use a valid SSL .... ' something here : manual.limesurvey.org/RemoteControl_2_API :)/
I say make a ssl valid key ios not LS related (and letsencrypt is great to have SSL validkey)
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic API: PHP Try to connect via RPC
Ogh think it's partially LimeSurvey manual relatedsarah_w wrote: @DenisChenu: Sorry just turned out now that it was not LimeSurvey related. But maybe someone has the same problem and this can help.
If you can found time to add a 'warning : if you don't use a valid SSL .... ' something here : manual.limesurvey.org/RemoteControl_2_API :)/
I say make a ssl valid key ios not LS related (and letsencrypt is great to have SSL validkey)
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- LouisGac
- Visitor
7 years 1 month ago #148937
by LouisGac
Replied by LouisGac on topic API: PHP Try to connect via RPC
also, I would recommend to use a Virtual Machine with LAMP stack rather than using the windows solutions.
The topic has been locked.
- risom
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
6 years 1 month ago #164370
by risom
Replied by risom on topic API: PHP Try to connect via RPC
I am having similar issues connecting from a shared web host. We are getting the exact same fatal error messages but our difference is our JsonRPCClient is being instantiated on a Linux machine and not Windows. It might be an SSL issue between our shared web host and our hosted LimeSurvey installation... but we are still looking into the issue.
The topic has been locked.