Issue understanding CouchBase connection with PHP - php

I just installed CouchBase and the .dll files for XAMPP. I am following their example on how to connect: "Hello Couchbase" https://developer.couchbase.com/documentation/server/current/sdk/php/start-using-sdk.html
This code:
$bucketName = "default";
// Connect to Couchbase Server
$cluster = new CouchbaseCluster("couchbase://127.0.0.1");
$bucket = $cluster->openBucket($bucketName);
gives me:
LCB_AUTH_ERROR: Authentication failed. You may have provided an invalid username/password combination
I have a fresh installation, and following their guide #1, what am I doing wrong? I don't remember setting a password, I went to the CouchBase admin page and I can't find a way to change any password.

I sympathize here -- I'm having the same error (and no, it's not you, the docs have been neglected). Instantiating the CouchbaseCluster doesn't throw the error, it's actually the openBucket() method that causes problems, and for me, the problem was that the bucket didn't exist (it would be nice if the Couchbase error were in the right ballpark instead of bumbling around in irrelevant confusion). Here's some code that worked for me:
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
$manager = $cluster->manager('MYUSER', 'MYPASSWORD');
$manager->createBucket('new_bucket');
This does throw some errors:
[cb,WARN] (htconfig L:130 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming terse URI not supported on cluster
[cb,EROR] (htconfig L:122 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got 404 on config stream. Assuming bucket does not exist as we've tried both URL types
[cb,EROR] (htconfig L:142 I:0) <couchbase:8091> (CTX=0x5601e6fd7e90,bc_http) Got non-success HTTP status code 404
But it does work. The Couchbase forums are a better place for these types of questions -- they respond pretty quickly over there.

Related

Error "Couldn't reach API" when I try to log in

I install Directus CMS via git clone successful. In the database 15 tables were created. In /config folder my projectkey.php file were created too.
After installation I want to login with my credentials and get the error "Couldn't reach API".
In PHP Error log -> no entry
In Directus log -> no entry
REST calls:
authenticate/ -> Code 200; Response: data/user
projectkey/ -> Code 200; Response: data/api
ping/ -> Code 200; Response: Pong
In a working instance I have seen that in API Call projectkey/ are more properties. For example data/server is missing in my instance.
Does anyone have any idea what this could be?
Version 8.5.X solved my problem
I had the same error and found the solution in the project's corresponding issue:
Check that you're using HTTPS on webservers and local... that is a new requirement added in 8.7.2 due to a cookie policy change by Chrome et al. If it STILL is an issue, please open a new ticket with exact/specific information. Thanks! 👍
Also, just as a reminder, this is a VERY generic error and could shown for several different root causes. More specific error handling/codes is something we're adding in v9.
Enabling SSL fixed it for me.

PHP Composer using define

I am using phpseclib to do some SFTP stuff. At the moment I can't login, and I am trying to find out why. In the docs, it states I should do something like this
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include 'Net/SFTP.php';
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new NET_SFTP('***');
if(!$sftp->login('***', '***')) {
print_r($sftp->getSFTPErrors());
}
So, I need to define the type of logging in order to print out the SFTPErrors.
I am doing things differently than the above because I am using composer. So as usual, I load autoload.php. Instead of include, I make use of use e.g.
use phpseclib\Net\SFTP;
I then proceed to do something like the following
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new SFTP($config::SFTP_SERVER);
if(!$sftp->login($config::SFTP_USER, $config::SFTP_PASSWORD)) {
print_r($sftp->getSFTPErrors());
exit('Login Failed');
}
If I do this however, I get the output
Notice: Use of undefined constant NET_SFTP_LOG_COMPLEX - assumed 'NET_SFTP_LOG_COMPLEX' in ...
Array
(
)
Login Failed
So it appears that with composer, I cant define a constant in the same way, and the print out of the errors produces an empty array.
So, how can I define this constant in my composer project?
Thanks
A few of things.
If you're using the namespaced version of PHP (as evidenced by your use phpseclib\Net\SFTP;) then you're using the 2.0 branch. The documentation on the website is for the 1.0 branch. For the 2.0 branch you need to do as Félix Saparelli suggested - SSH2::LOG_COMPLEX.
That said, logging isn't going to show SFTP errors. Logging shows you the raw packets. Here's an example of what the logs produce:
http://phpseclib.sourceforge.net/ssh/log.txt
You get these logs by doing $ssh->getLogs().
For the errors you don't need to enable anything - it places any errors it receives from the server into an array that it's returning to you. phpseclib does this automatically and this behavior cannot be disabled.
Also, $sftp->getSFTPErrors() is great for SFTP errors but at the login process you might be getting SSH errors and not SFTP errors. You'd get SSH errors by doing $sftp->getErrors(). The thing is... SFTP operates in a higher layer than SSH. SSH won't succeed if TCP/IP can't make a connection and SFTP won't succeed if SSH can't make a connection. So per that you ought to be checking all the layers.
Finally, it's quite possible the failure is happening for reasons for which errors would not be returned. Maybe the server requires compression, which phpseclib doesn't support. eg.
http://www.frostjedi.com/phpbb3/viewtopic.php?p=221481#p221481
I also don't know if you'd get an error if the key or password you were using was simply invalid.
Really, there could be any number of causes for an inability to connect. You could be using selinux which, by default, disables outbound connections from PHP scripts running on port 80, there could be a routing issue, etc (all of these affect fsockopen, but, in all, there are just a lot of potential causes for failure).
Overall, I'd say you're on the right track with the logs. But do $sftp->getLog() instead of $sftp->getSFTPErrors() and then include the logs in your post.

Google Calendar API with a Service Account Problems

I've been trying for days to get Google's Calendar PHP API working on my local Laravel development site. Here's the problem:
I'm using a service account so I can perform functions on one calendar (the service accounts calendar). I'm not authenticating users and requesting access to their calendar.
I've verified everything from my client ID, the service email address, the key.P12 file, still nothing happens.
Here is my code:
$key = File::get($this->key);
$credentialObj = new \Google_Auth_AssertionCredentials(
$this->serviceAccountName,
array('https://www.googleapis.com/auth/calendar'),
$key,
'notasecret'
);
$client = new \Google_Client();
$client->setApplicationName($this->applicationName);
$client->setClientId($this->clientId);
$client->setAssertionCredentials($credentialObj);
\session_start();
$calendarServiceObj = new \Google_Service_Calendar($client);
$events = $calendarServiceObj->events->listEvents('mygmail#gmail.com');
dd($events->getItems());
I've even tried using Google's own example here:
https://github.com/google/google-api-php-client/blob/master/examples/service-account.php
No errors, nothing. Just a blank error page every single time. I've tried so many examples all over the internet, even here on stack overflow, and at the end, all I get is a 'This webpage is not available'. This happens on every browser.
Laravel is set to development mode so all errors are displayed, and I've even force set the ini using ini_set("display_errors", 1);.
I know everything works fine up until I request anything from the service object. All the calendar api's are set to on in my developer account. Does my local development domain need to have SSL enabled?
It be so nice if I could figure out at least what is going on, but with this obscure error, I have no idea.
If anyone has any tips, I'd really appreciate it. Thanks!!
EDIT: I've scoured through googles API code, and this is exactly where the request fails:
vendor\google\apiclient\src\Google\Signer\P12.php
Line 77 to 92:
public function sign($data)
{
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
throw new Google_Auth_Exception(
"PHP 5.3.0 or higher is required to use service accounts."
);
}
$hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
//If I die(); here, I receive the response
if (!openssl_sign($data, $signature, $this->privateKey, $hash)) {
//Something happens here, or inside the openssl_sign command, I never reach the exception
throw new Google_Auth_Exception("Unable to sign data");
}
//It never reaches here
return $signature;
}
In my PHP Info:
Solved by updating PHP. I was using Softaculous AMPPs 2.3 with PHP 5.4.27. Upgrading to AMPPs 2.6 fixed the issue. My Open SSL in my config is now:
Nothing was done to my code above since, and it now works. This was definitely an open ssl issue. Anyone receiving an ERR_CONNECTION_RESET must update their open_ssl version.
I hope this helps anyone trying to figure this out.

Owncloud webdav access from php

I'm trying to access my owncloud webdav interface and get the list of files in the root directory from PEAR WebDAV Client. I'm trying the following:
include("HTTP/WebDAV/Client.php");
$client = new HTTP_WebDAV_Client_Stream();
$user="admin";
$pass = "q1w2e3r4";
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
$stuff = $client->dir_opendir($dir, array());
var_dump($stuff);
var_dump($client->dirfiles);
The code print false, false, and when I've tried to debug it, I saw Connection refused error in Socket.php, when it tried to call the function
fsockopen("127.0.0.1", 10081, $err, $errstr);
It's even more strange since I can access this server and list the directories from cadaver though. Also I can access the test DAV server with my code by replacing my $dir variable:
$dir = "webdavs://".$user.":".$pass."#127.0.0.1:10081/owncloud/remote.php/webdav/";
It's an ugly hack, but if you add something similar to:
var_dump($err->getMessage());
to /usr/share/php/HTTP/Request.php on line 739, you should be able to see the most relevant error message. (If that is where Request.php got installed to.)
Unfortunately, there doesn't appear to be a mechanism in place in the underlying HTTP_Request package for raising that specific error message back to the HTTP_WebDAV_Client_Stream code.

Soap error when trying to use the API of Magento

I am looking for help with this problem and I hope someone give me that help. The error is the following:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com/index.php/api/?wsdl' : failed to load external entity "http://example.com/index.php/api/?wsdl" in
/var/www/presentacion/app/code/local/Pengo/Extension/Model/Something.php on line 28
And the code that I'm using to connect to it is something like this:
$this->_soap = new SoapClient(http://example.com/index.php/api/?wsdl);
and there is where it says is the error.
I have been serching in Google, PHP forums, here in StackOverflow and Magento itself but I don't find the solution anywhere.
What I had seen is that the WSDL is never get parsed or loaded as the error says and none of its functions.
I tried connecting like this:
$options['location'] = http://example.com/index.php/api/?wsdl;
$options['uri'] = 'urn:Magento';
$this->_soap = new SoapClient(null, $options);
like this it doesn't dispatch any error like the others but there aren't functions to use, like in the other case it doesnt' load and parse the WSDL.
I am a bit frustrated because I have been developing this like 1 month and now that I am making some tests it shows this message, I had test it when it was really empty and new and it worked fine.
So any help would be appreciated.
Thank you.
Nine times out of ten this error is Magento is telling you it can't load the WSDL file. Magento is telling you this. It's not your local client code that's complaining.
Magento uses the PHP SoapServer object to create its SOAP API. The SoapServer object needs to access the WSDL as well. Try running the following from your server's command line
curl http://example.com/index.php/api/?wsdl
If I'm right, the above will timeout/fail.
Because of some quirks in DNS, it's surprisingly common that a server won't be able to access itself via its domain name. If this is the case, the quickest fix is adding an entry to the server's hosts file. (Talk to your server admin if none of that made sense)
Well after all the things that I test the only one that worked for me, I don't know why but it worked, was doing this in two separate machines. I tried that because I read that somewhere and I just do it and my Magento and Webservice now works perfectly. Whenever I try to do this local it dispatch the same error.
I hope this can help someone in the future and they don't have to knock their head on the wall because of this problem.
Thank you all for your answers and comments.
Alan Storm is right on the Money here!
Make sure that you check your server Hosts File, and that it includes an entry for both domain and www.domain. Espicialy important if you are doing server rewrites.

Categories