phpBB3 with Memcached


Fowler

Recommended Posts

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.

Link to comment
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.

Link to comment
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');
}

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 6 months later...
On 3/29/2017 at 2:59 AM, Fowler said:

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.

Did you ever get this working?

Link to comment
Share on other sites

No i never managed to get this working.  On my previous host that gave an IP/port it worked flawlessly and easily but with the set up here I could only get either a slow page load where nothing was being cached (visible by the high number of queries) or where it would just keep loading forever and day it seemed.  I just thought it was not worth the effort to get it to work in the end.

Link to comment
Share on other sites

7 hours ago, Fowler said:

No i never managed to get this working.  On my previous host that gave an IP/port it worked flawlessly and easily but with the set up here I could only get either a slow page load where nothing was being cached (visible by the high number of queries) or where it would just keep loading forever and day it seemed.  I just thought it was not worth the effort to get it to work in the end.

We have plenty of users with various applications utilizing memcached.  I'd suggest opening a ticket and asking it to be assigned to me and I'll see if I can determine why it's not working.

Unfortunately a lot of applications don't give clear instructions how to use memcached feature when the memcached server has to be accessed by socket.  Considering the amount of servers where more than one user is on it utilizing ip/port with no authentication is a very bad idea.  It would be easy for another user to read and even write data to your memcached instance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...