Fowler

phpBB3 with Memcached

6 posts in this topic

Hello,

 

I am trying to configure a test forum to use Memcached but I can not get it to work due to the Unix socket given rather than an IP that phpBB works nicely with.

https://raw.githubusercontent.com/phpbb/phpbb/master/phpBB/phpbb/cache/driver/memcached.php

This is the default settings for memcached in phpBB3 which obviously don't work and result in slow load times and not caching queries (after a few refreshes)

Time: 0.583s | Queries: 23 | Peak Memory Usage: 7.29 MiB

No matter what I seem to try, it always doesn't seem to work resulting in the same similar slow load generation times and high number of queries and peak memory usage signifying it doesn't work.

Using the default phpBB file cache, generation times and query counts for the same page (after a few refreshes) are

Time: 0.047s | Queries: 10 | Peak Memory Usage: 2.61 MiB

So when memcached works, it should be similar to those values.

Is there a traditional IP/port i can use to get this to work or do you know of a way to get it to work?

BTW ideally I want to use php7 and memcached but I have also tried with php 5.6 and memcache with the same results.

Share this post


Link to post
Share on other sites
6 hours ago, Fowler said:

Is there a traditional IP/port i can use to get this to work or do you know of a way to get it to work?

The reason we do not offer a traditional IP/port is because anyone on the same server as you could read your memcached data.  This would be a security risk which is why it's a socket that exists only inside your own accounts Cage meaning only you can access it.

6 hours ago, Fowler said:

BTW ideally I want to use php7 and memcached but I have also tried with php 5.6 and memcache with the same results.

I want to clarify one thing the recommended extension is memcached and not the memcache extension.  The memcached extension is actively developed:

https://pecl.php.net/package/memcached

The memcache extension is not:

https://pecl.php.net/package/memcache

The last release is almost four years ago.

6 hours ago, Fowler said:

Hello,

 

I am trying to configure a test forum to use Memcached but I can not get it to work due to the Unix socket given rather than an IP that phpBB works nicely with.

https://raw.githubusercontent.com/phpbb/phpbb/master/phpBB/phpbb/cache/driver/memcached.php

Looking at their code directly I believe we can make this work with sockets.  What you can do is use the following:

unix:///path/to/memcached.sock

The reason I'm coming to this conclusion is

$this->memcached->addServer(trim($parts[0]), trim($parts[1]));

They are calling the PHP extension and the documentation for addServer is here: http://php.net/manual/en/memcache.addserver.php  and it accepts sockets on the host and you set the port to 0.

That should make everything work when you utilize the Memcache extension in PHP 5.6.  Unfortunately looking through the phpbb forums there is no support for the memcached extension meaning you cannot utilize PHP 7.

Share this post


Link to post
Share on other sites
2 hours ago, Tony said:

The reason we do not offer a traditional IP/port is because anyone on the same server as you could read your memcached data.  This would be a security risk which is why it's a socket that exists only inside your own accounts Cage meaning only you can access it.

The reason I said that was because in the blog post it contained a local IP and a non default port so I assumed it was possible in some way - http://blog.hawkhost.com/2015/12/31/memcached-now-available-on-all-hosting-plans/comment-page-1/

2 hours ago, Tony said:

I want to clarify one thing the recommended extension is memcached and not the memcache extension.  The memcached extension is actively developed:

https://pecl.php.net/package/memcached

The memcache extension is not:

https://pecl.php.net/package/memcache

The last release is almost four years ago.

phpBB had memcache available and as it wasn't available for php7, I wanted to see if I could get that to work with 5.6 but php 5.6 with memcache and php 7.1 with memcached both had the same results.

2 hours ago, Tony said:

That should make everything work when you utilize the Memcache extension in PHP 5.6.  Unfortunately looking through the phpbb forums there is no support for the memcached extension meaning you cannot utilize PHP 7.

It is now available in phpBB which is the file I linked to. You can see both memcache and memcached listed here - https://github.com/phpbb/phpbb/tree/master/phpBB/phpbb/cache/driver

I tried the following which didn't work

	namespace phpbb\cache\driver;
	if (!defined('PHPBB_ACM_MEMCACHED_PORT'))
{
    define('PHPBB_ACM_MEMCACHED_PORT', 0);
}
	if (!defined('PHPBB_ACM_MEMCACHED_COMPRESS'))
{
    define('PHPBB_ACM_MEMCACHED_COMPRESS', true);
}
	if (!defined('PHPBB_ACM_MEMCACHED_HOST'))
{
    define('PHPBB_ACM_MEMCACHED_HOST', 'unix:///home/USERNAME_HERE/.hostdata/memcached.sock');
}

Share this post


Link to post
Share on other sites
5 hours ago, Fowler said:

The reason I said that was because in the blog post it contained a local IP and a non default port so I assumed it was possible in some way - http://blog.hawkhost.com/2015/12/31/memcached-now-available-on-all-hosting-plans/comment-page-1/

Our original setup was over IP/Port but had switched it to socket and updated our documentation.  I updated the text description for that as well now and we'll see about just updating the pictures as well.

As for the issue at hand I'd suggest opening a ticket if you still cannot connect to the memcached socket as the code there shows it supporting it.  So it's possible the memcached instance on your account is not starting up properly or something similar.

Share this post


Link to post
Share on other sites

Quick update.

Using the memcached phpbb cache plugin and php7, I changed the add server line you quoted above to the following

$this->memcached->addServer('/home/USERNAME_HERE/.hostdata/memcached.sock', 0);

unix:// is not needed as explained here for memcached as it is memcache specific - http://php.net/manual/en/memcached.addserver.php

That resulted in a constant wait for the page to load.  It was literally taking for ever and nothing loaded.  I then changed my username slightly by adding another letter to it and immediately the forum became online again although slower with nothing being cached obviously.  It looks like when the connection info is correct, it just loads forever and a day. When the config information is wrong, it loads the forum but caches nothing so the site is slower. It looks like when the config info is correct, something is blocking it from working somewhere.  I may try memcache and php 5.6 again and see if it get the same constant loading when the config is correct but slightly changing the username in the path results in the site being visible again. The memcached plugin for phpBB is alot newer where as the memcache plugin has been available for years so that may work better if the issue is with phpBB. 

I can't really set up a ticket at the moment but not a major issue at the moment for me. Just was going to use it as it was available and thought it was going to be easy to use.

Share this post


Link to post
Share on other sites
8 hours ago, Fowler said:

I can't really set up a ticket at the moment but not a major issue at the moment for me. Just was going to use it as it was available and thought it was going to be easy to use.

In that case if you're comfortable with SSH what I recommend doing is we kill the current memcached instance and then start it back up.  So if you login to SSH you can run:

ps axu | grep memcached


Then you should see something like this:
 

607       802829  0.0  0.0  66600   940 ?        Sl   11:07   0:00 /usr/bin/memcached -B ascii -m 64 -s /home/memcachedtest/.hostdata/memcached.sock

You'll then want to kill the process so in my case I'd run
 

kill 802829

Then if you do another ps axu | grep memcached you should no longer see the memcached instance running.  You will then want to turn it back on in cPanel then hopefully this time around it's operating properly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now