Closed zurnet closed 5 years ago
Currently I don't test a connection over https
but for this couchdb must know a ssl certificate
I my mind this must work fine
Yes it definitely will work. For example, Cloudant uses https.
Have you tested this? if I have just http:// it works, but the moment i change it to: https:// I get this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'no data to parse' in /lib/PHP-on-Couch/couch.php:140 Stack trace: #0 /lib/PHP-on-Couch/couchClient.php(156): couch::parseRawResponse(false, false) #1 ]/lib/PHP-on-Couch/couchClient.php(779): couchClient->_queryAndTest('GET', '/db_name/_de...', Array, Array, NULL) #2
can you give us a code snippet what your try correctly. And are your sure the CouchDb Server listen over SSL? Without the SSL configuration this can't work!
My apologies... when I do a simple test outside of my code it seems to work, but within the framework I built, it throws an error... will have to do more digging.
ok, if your have more information about this error case please notify us.
Basically, CouchDB supports https. Normally you will need to have a cert for this.
but I'm afraid this might not be build here in PHP-on-couch? It's nowhere to be found in the doc. I might be wrong on this, since I haven't try https connection using PHP-on-couch yet.
I think I have it working, for future reference... if you're trying to do it on a localhost, you'll probably run into errors. Also, if you're using a cname record that connects to host serving up couchdb, it'll throw errors as well. Probably obvious, but frantically changing things and them not working, it's easy to overlook.
There is a new issue that has come up, causing phponcouch not to work. I don't know if this is from an upgrade to couchdb (I believe so)
Array ( [scheme] => https [host] => yourUser.cloudant.com [user] => yourUser [pass] => yourPassword [port] => 80 ) does NOT get returned from one of my connections to cloudant using Moonshine—SoftLayer
All that gets returned from that section is: Array ( [port] => 80 )
Anyone else experiencing this, I have a database in use constantly that is down because I'm getting the same error posted earlier in this thread, relating to returning no data. I believe it is because cloudant isn't returning the scheme, host, user etc etc... just the port number.
My setup is still running, haven't received any failed report yet. Can you check if this has nothing to do with your permission level?
The only way I was able to fix it, was to create a new username on cloudant and replicate the data over. For some reason, the username I had when printing out the $client info gave me this:
[dsn_parsed:protected] => Array ( [port] => 80 )
When I should've been returned:
[dsn_parsed:protected] => Array ( [scheme] => https [host] => username.cloudant.com [user] => username [pass] => XXXXXXXXXXXXX [port] => 80 )
If you know of any reason why scheme, host, user, and pass are not returned, that would be helpful, but afaik it's up to couchdb/cloudant to return that other info, not just the port.
@zurnet what did you do to get connect to cloudant db using https?
I'm running into the exact same issue as you stated in your March 14 2014 statement. If I run my php code from command line it works. But when I try to access the php via browser (php served up using apache via xampp) I get the Fatal error: Uncaught exception 'InvalidArgumentException' with message 'no data to parse'
Here's simple code example:
<?php require_once('./lib/couch.php'); require_once('./lib/couchClient.php'); require_once('./lib/couchDocument.php');
$client = new couchClient ('https://username>:<password>@<host:443','
// Get all docs
$all_docs = $client->getAllDocs();
echo "Database got ".$all_docs->total_rows." documents.
\n";
foreach ( $all_docs->rows as $row ) {
echo "Document ".$row->id."
\n";
}
?>
So here's things working via the command line (password clipped for obvious reasons):
And here's the error seen when accessing via browser:
@jrwashbu
The basics of it is you should run couchdb locally and access it via HTTP. On the web server, use HTTPS. Simply use an IF statement to understand if you're local or on the web.
if(strpos($_SERVER["SERVER_NAME"], '.loc') == true){
$client = new couchClient ('http://USER_NAME:PASS_WORD@127.0.0.1:5984','YOUR_DB_NAME');
} else {
$client = new couchClient ('https://USER_NAME:PASS_WORD@CLOUDANT_USER_NAME.cloudant.com','YOUR_DB_NAME');
}
hello all! im getting the same issue "no data to parse" in laravel 5 and i dont know how to solve or what im doing bad.. require_once app_path().'\Couch\lib\couch.php'; require_once app_path().'\Couch\lib\couchClient.php'; require_once app_path().'\Couch\lib\couchDocument.php';
$client = new couchClient ('https://X:Y@X.cloudant.com:443','users');
$all_docs = $client->getAllDocs();
echo "Database got ".$all_docs->total_rows." documents.\n";
foreach ( $all_docs->rows as $row ) {
echo "Document ".$row->id."\n";
}
Thanks for the awnser zurnet; I've created another account in different location, when i put the url in the browser it prints {"couchdb":"Welcome","version":"1.0.2","cloudant_build":"2530"} but the same exception "no data to parse" when i run the php code. If i run var_dump with the $raw_data before the exception it prints "boolean(false)", and if i var_dump the response calling the url by curl via php a get the same "boolean(false)".
You've created a db, a view of some sort and added some records already yes?
yep
Can you get it to run locally?
$client = new couchClient ('http://user_name:pass_word@127.0.0.1:5984','THE_DB_NAME');
?
Also, as far as I know cloudant runs without that port number,so for example:
$client = new couchClient ('https://user_name:pass_word@sub_domain.cloudant.com','the_db_name');
sorry i didnt create the view but now yes, i remove the port from the url and get the same exception.
and this is how i try to connect: $client = new couchClient ('https://socpa:asdargonnijao@socpa.cloudant.com','users');
i dont care about the credentials because this is for educational purposes so maybe you can help me more find out what happens.
i tried locally and it works fine.
Thanks!
this works for me:
<?php require_once "inc/libs/PHP-on-Couch/couch.php"; require_once "inc/libs/PHP-on-Couch/couchClient.php"; require_once "inc/libs/PHP-on-Couch/couchDocument.php"; require_once "inc/libs/PHP-on-Couch/couchReplicator.php";
$client;
$client = new couchClient ('https://socpa:asdargonnijao@socpa.cloudant.com','users');
$db_get_recs = '';
$db_get_recs = $client;
$db_get_recs = $db_get_recs->include_docs(FALSE);
$db_get_recs = $db_get_recs->asArray();
$db_get_recs = $db_get_recs->getView('default','new-view');
print_r($db_get_recs);
?>
Not for me... it means that is a problem with laravel :S have you got any idea?
sorry do not know much about laravel
okey, thanks a lot man!
mmm im trying to get your code outside of laravel, in xampp but i get the same exception
hmmm not too sure exactly... forgive me I'd have to think about it more.
Into .env file add:
CURLOPT_SSL_VERIFYHOST=0 CURLOPT_SSL_VERIFYPEER=0
You have to add both! I do use HTTPS but my cert is not trusted so when I added these options, everything works...
If you have not .env file then for fast fix add these options to CouchHttpAdapterCurl::buildRequest() method...
.env files are not supported in this repository.
Be sure to set verify_ssl_certificates = true
and fail_if_no_peer_cert = false
in the CouchDB local.ini if you are supplying a CAcert file. Not doing so resulted in issues with verifying the peer and that broke PHP on Couch for me.
Is it possible to connect to the couch db using https:// If I try http:// it works fine, but if I try https:// it does not?