I've noticed MySQL could use Memcached NoSQL with InnoDB but I can't retrieve information about how to use it.
I want to use with PHP.
Are NoSQL queries standard?
First of all, MySQL only support memcached with NoSQL since version 5.6. Today this version it's not update yet in linux repositories and must be manually installed, specially in servers, e.g. MySQL --version (ubuntu) is 5.5.38 ; (RedHat server) 5.1
You also must install libevent-dev e.g:
Still some hacks are needed, and you must install memcache interface plugin for MySQL located in $MYSQL_HOME/share.
I found a well explained post how to install and try it:
http://chipersoft.com/p/MySQL-via-Memcache/
Due to its young state, it's not for production servers.
Use it with PHP is easy because memcache is a native module in PHP when you have php5-cli and php5-memcache installed:
<?php
$memcache = new Memcache;
if (!$memcache->connect('localhost', 11211)) throw new Exception("Could not connect");
if (!$memcache->set('bar', 'John|Smith')) throw new Exception("Could not store value");
$memcache->get('##aaa'); //switch containers
$result = $memcache->get('AA');
var_dump($result);
Conclusion, this method let you work with MySQL and NoSQL simultaneously. Memcache offers a quick, NoSQL way to retrieve and work with data in a well different manner than SQL.
Edit: Another useful link was this post by Tony Darnell
Related
I'm trying to connect PHP 7 with mongoDB, I installed the "new" MongoDB driver using pecl by following this page instructions. I can see MongoDB version 1.1.8 from phpInfo() output, but I can't figure out how to initiate a connection from PHP code :p . the following code includes my attempts to connect (tried to connect even using old fashion way)
// new fashion way
$connection = new MongoDB\Driver\Client();
// or by using old fashion way
$conn = new MongoClient();
// random try :p
$randConn = new MongoDB\Client();
and in both cases, I'm getting not defined class exception.
please let me know what I'm missing and where is my mistake, please provide and example to be easier to follow if possible ;) .
PS: used operating system is ubuntu 14.04 LTS.
thanks in advance.
The page that you are referring to is the low-level PHP driver for MongoDB. The API is the same as the HHVM driver for MongoDB. The documentation for both of them is the same, and can be found at http://docs.php.net/manual/en/set.mongodb.php
The driver is written to be a bare bone layer to talk to MongoDB, and therefore misses many convenience features. Instead, these convenience methods have been split out into a layer written in PHP, the MongoDB Library. Using this library should be your preferred way of interacting with MongoDB.
The library needs to be installed with Composer, a package manager for PHP. See also Get Composer: Installation on Linux/OSX
For example:
composer require "mongodb/mongodb=^1.0.0"
Once you have it installed, you can try connecting using:
<?php
require 'vendor/autoload.php';
$collection = (new MongoDB\Client("mongodb://127.0.0.1:27017"))->dbname->coll;
?>
See also:
Doc: MongoDB PHP Library
MongoDB PHP Library: Getting Started
PHP MongoDB Driver
I have MongoDB installed in my cPanel/WHM CentOS server.
I have the PHP Drivers installed.
I have Port 27017 opened.
This works $m = new MongoDB\Driver\Manager();
These do not work:
$m = new Mongo();
$m = new MongoClient();
Both result in Fatal error: Class 'Mongo' not found in ... and Fatal error: Class 'MongoClient' not found in ....
Does anyone know why?
Not a duplicate. That SO Q is for a Windows machine. My server is Linux/CentOS
From My Hosting Provider's Sys Admin:
It looks like "mongo" is a seperate php module from "mongodb", and that "mongodb" is the newer one:
root#host [~/support/642192]# pecl search mongo
Retrieving data...0%
.Matched packages, channel pecl.php.net:
Package Stable/(Latest) Local
mongo 1.6.12 (stable) MongoDB database driver (legacy)
mongodb 1.1.2 (stable) 1.1.2 MongoDB driver for PHP
Did you need the legacy module "mongo" instead of "mongodb"? Here is hte pecl page for the package you have:
https://pecl.php.net/package/mongodb
and here is the one for the legacy module:
https://pecl.php.net/package/mongo
Short answer
You cannot use the following classes with the new mongodb driver:
$m = new Mongo();
$m = new MongoClient();
This corresponds to the legacy mongo driver. Instead you should use MongoDB\Client through the MongoDB PHP Library.
Long answer
All right. I lost some hair on this story as well, because the documentation about Mongo and PHP is extremely confusing. The options are then to get mad, bald, or both. But i found courage and finally got it. So this might help you.
1. MongoDB driver: mongo vs mongodb
First of all, you must clarify which MongoDB driver you use: either mongo (legacy) or mongodb (new). Note the smaller case. First source of confusion, the mongo driver is sometimes referred to as MongoDB (legacy) PHP driver.
https://docs.mongodb.com/ecosystem/drivers/php/
Second source confusion, the version numbers are not logical, as mongo driver had 1.5, 1.6 but mongodb starts again from 1.0. So, going forward, but backwards, it's just insane... Imo they should have started from 2.0!
The choice of the driver depends on your PHP version:
PHP5.3: you can only use the mongo legacy driver (1.5, 1.6)
PHP7.0: you can only use the new mongodb driver (1.1+)
PHP5.4, 5.5, 5.6: here you have the choice between the old mongo (1.5, 1.6) or the new mongodb (1.0, 1.1+)
But it's not over. The driver is just a low-level interface (aka PHP extension). Now we come to the programmer's API and it becomes even worse.
2. API: MongoClient vs MongoDB\Driver
Third source of confusion, the low-level drivers and the API classes have overlapping names.
mongo legacy driver -> classes MongoClient, MongoDB (!), ...
mongodb driver -> classes MongoDB\Driver, MongoDB\BSON, ...
But it's not over yet. The old mongo driver could be used directly. The new mongodb driver provides classes (such as MongoDB\Driver) but it is actually a low-level API. You are not supposed to use it directly, you could, but it's not convenient. Instead you should use the MongoDB PHP Library which gives an API similar to the old MongoClient classes...!
3. MongoDB PHP Library (with mongodb) -> MongoDB\Client
https://docs.mongodb.com/php-library/master/
So if you installed mongodb, you should install this MongoDB PHP Library in order to use MongoDB\Client. This class is supposed to be similar to the old MongoClient, but there are some differences such as the sort and projection.
To install this library you are advised to use the tool called Composer which allows to you download these classes into your repo. Then use the autoloader provided with Composer.
And here we come to the 4th source of confusion, MongoDB PHP Library is versioned from 1.0 even though you are using the last mongodb driver in version 1.1 ! It's certainly obvious for those who developed this stuff but very hard to follow for lambda users. Crazy confusing stuff.
There are also many other libraries above the drivers, but i don't know them at all so i won't go more into them (https://docs.mongodb.com/ecosystem/drivers/php-libraries/).
TL;DR
Depending on your PHP version, clarify which MongoDB driver to use: mongo (legacy) or mongodb (new) ?
with mongo you can use MongoClient class directly.
with mongodb you should also install MongoDB PHP Library to use MongoDB\Client class.
Good luck! :)
Looks like you haven't enabled or installed php_mongo extension.
After enabling it restart apache and check phpinfo() to see if its properly enabled.
You have use the correct namespace. As stated in their docs the namespace for the client is MongoDB\Client. Alterantivly you can use a use statement like this use MonogoDB\Client.
I have two RHEL servers, one to host the PHP application, one to host the MySQL server.
Database server has MySQL Enterprise version 5.6.21 installed.
While getting the application server built, I asked that the rpm MySQL-client-advanced-5.6.21-1.el6.x86_64 be installed (to match server), but the hardware people don't like this version since 5.6.27 is available which addressed some vulnerabilities.
The question is the following:
Does the mysql client version on the application server affect the database queries coming from the PHP application?
We're using PDO to connect to and query MySQL.
If we do this, does the application server even need a mysql client library?
Please let me know if I can clarify.
Thanks!
PHP uses its own library/driver to connect to MySQL databases. The MySQL-client-advanced package is just the CLI mysql client. PHP does not use this.
For PHP (and PDO), you should install php-pdo and php-mysqlnd. php-mysqlnd is the "MySQL native driver" and contains some enhancements. It also contains the mysqli class and the pdo-mysql connector.
Note: php-mysqlnd versions are unrelated to the MySQL server version.
Quote from the Mysql website
MySQL Native Driver is a replacement for the MySQL Client Library (libmysqlclient). MySQL Native Driver is part of the official PHP sources as of PHP 5.3.0.
https://dev.mysql.com/doc/apis-php/en/apis-php-mysqlnd.html
Sorry but, I've searched this question and I found a lot of old answers.
Now, I can use memcacheD instead of memcache on windows?
http://www.codeforest.net/how-to-install-memcached-on-windows-machine
I installed php_memcache.dll extension and memcached.exe server service, but this is memcache! (without "D"). in fact if I use
new Memcache;
it works fine, instead if I use:
new Memcached;
or
new MemcacheD;
doesn't work.
I would like to implement memcacheD (with "D" !!!) because I will use it on amazon Elasticache together Zend Framework Cache/Session and it works with memcacheD. Now I'm working in Xampp (windows) ambient. How to work with memcacheD in windows? I need another libraries?
Thanks a lot, I'm fighting for using this -.-
I'm using Win7 (64bit).
My DDL file is available here (php 5.6 - 5.6 Thread Safe (TS) x86):
http://pecl.php.net/package/memcache/3.0.8/windows
My memcached server version is 1.4.4 32bit version, available here
http://blog.elijaa.org/index.php?post/2010/10/15/Memcached-for-Windows&page
You're confusing the two. memcached is the Memcache daemon program (the d stands for daemon). This has to be running for you to use Memcache. This is NOT what you use inside PHP. You launch this inside Windows like you would any other program.
The Memcache PECL library is how you can connect to your running daemon. You use new Memcache inside PHP to create an object that connects to the daemon and then interacts with it.
I've been struggling with this myself, and it seems that the only solution is to compile the DLL yourself from source, because there are no official Windows binaries for the PHP memcached extension available. This is a related question: Does memcached.dll exist?
I followed the instruction in this tutorial on how to install nginx, php, and mysql including the php5-memcache.
I'm wondering if I still need to install the memcache or memcached without the "php5" prefix .
As of now my WordPress site is complaining the ff:
The following memcached servers are not responding or not running:
Page Cache: 127.0.0.1:11211.
Database Cache: 127.0.0.1:11211.
Object Cache: 127.0.0.1:11211.
This message will automatically disappear once the issue is resolved.
If it is needed to be installed, will it not conflict with php5-memcache? Or something like an overkill usage of the two version?
And what is the best version to use? Memcache or Memcached? php5-memcache or php5-memcached.
I heard that memcached with "d" is just a service or daemon. But somebody is trying to compare the two as what I have seen here.
The names of these extensions are confusing.
Actually, both php5-memcache and php5-memcached are PHP extensions for working with the memcached service (Memcached server). They both give your PHP processes, the ability to be clients to the memcached service, i.e. to connect to memcached over the network, and to speak the memcached protocol, in order to use the memcached API.
The php5-memcached extension is more stable and has more features in my opinion, so I would suggest, that it should be tried first. Most of its operations are faster too (php source for the benchmark that produced these results).
You still do need the actual memcached service started somewhere, and its address, in order to connect to it. The memcached service may be started on the same host, or on another host/hosts, if you want a distributed cache.
memcache and memcached are 2 different servers, each has some features and stuff, you can read the differences as there's so many previous questions about that check google search
The ones starting with php are the extentions used to access the service, just like to use mysql you need php5-mysql, and to use curl you need php5-curl.
So you have php5-memcache for memcache, and php5-memcached for memcached, you can read about what each provide from those links: memcached lib and memcahe lib
EDIT: Just want to correct the wrong info I wrote above, both php5-memcache and php5-memcached connect to the memcached server, they are just different extensions for the same server, I guess just like php5-mysql vs php5-mysqli
You can still use both together, there's no conflict, but i believe you only need one not both, because most features are available with both, some provide little more features, another candidate service is redis, you should read into that too, it has some features not available in the memcached servers.