Delete old PHP5 session files automatically

If not specified the PHP5 session files will be located in a directory like /var/lib/php5 and the builtin garbage collection will delete them, normally after 24 hours.

But often systems like CMS:es will put session files somewhere else and if the system doesn’t have it’s own garbage collection those session files will be kept forever. The reason can be to let a website visitor click “keep me logged in” or to remember a visitors preferences on the website. This normally doesn’t impose a problem as these session files are very small and the number of them counts in hundreds or possibly a couple of thousand files.

However, I encountered a site that created a very large number of session files and kept them forever. At some point the session files count was in the range of millions of files causing the system to run out of inodes. A solution could be to investigate how the system was handling session files but the internal workings of the site was outside of my responsibility. Another solution was to increase inodes but this will be a temporary solution.

The solution chosen was to create a garbage collection routine for the site in question, that deleted session files older than x days. The oldest session files was over 4 years old. The decision was to delete all session files older than a month (30 days), causing visitors who logged in, or had their preferences set, for more than a month ago had to re-login or set their preferences again on their next visit to the site. This was accomplished by the following command (which is run by cron every night):

find /var/www/somedomain.com/web/var/session/ -type f -mtime +30 -exec rm {} \;

bigclivedotcom Youtube channel

bigclivedotcom is a Youtube channel operated by Clive from Isle of Man. He dissects and investigates all kinds of electronics stuff, mostly ordered from questionable eBay sources. If you are into electronics this is a really enjoyable channel.

Unwanted code is displayed on Joomla articles when caching is enabled

Unwanted code, like below, is displayed on articles when System -> Global settings -> Cache is set to ON (both for conservative and progressive caching). The first time the article is loaded it looks ok but when reloading it garbage code like below is displayed. System is Joomla 3.4.8.

Example of unwanted code displayed:

{idkey=7001b0[url=http%3A%2F%2Fsomedomain.com%2Fom-site][title=Om+oss][desc=+%7Bloadposition+undermeny_4_text%7D+%7Bloadposition+undermeny_4_bild%7D+]}{cmp_start idkey=9514[url=http%3A%2F%2Fdomedomain.com%2Fom-site][title=Om+oss][desc=+%7Bloadposition+undermeny_4_text%7D+%7Bloadposition+undermeny_4_bild%7D+]}

This is generally caused by a third party plugin. To track down which one is causing this you need to disable plugins one by one and clear the cache before reloading (reload at least twice).

In my case, it was a plugin called Content – Facebook-Twitter-Google+1 causing the trouble. I tried reordering the plugin, from first to last without any success so I simply just had to ditch it and find another one.

I found out that the BT Social Sharing plugin was a better alternative. Apart from not giving the above trouble it doesn’t slow down the site as the Facebook-Twitter-Google+1 plugin did.

Telldus net and NEXA PER-1500 remote controlled switch

The NEXA PER-1500 remote controlled switch works fine with Telldus net. This unit does not have a learn button. Instead it goes into learn mode for about 5 seconds when power is applied and that is indicated by the LED blinking. To add the NEXA to to Telldus Live:

  • The NEXA PER-1500 should be disconnected from power
  • Log in to Telldus live and add new device
  • Select NEXA -> Self learning on/off
  • Power on the NEXA PER-1500 and immidiately click the Learn button in Telldus Live. You might need to hit it a couple of times.
  • The NEXA PER-1500 will click it’s relay to verify the pairing

Troubleshooting:

  • The NEXA PER-1500 can be paired to maximum 6 devices. If you are not certain there is a free memory slot, clear all memories by using the remote control. Power on the NEXA PER-1500 and while the LED is blinking you hit ALL OFF on the remote control
  • When pairing the NEXA PER-1500 with Telldus net it needs to be very close to the unit (I paired it within 1 meter from it). When paired it will work on further distances.

Joomla 1.5 PHP fatal error allowed memory size exhausted in libraries/joomla/error/exception.php [SOLUTION]

After a site move (from one webhosting to another) the site reported error 500 internal server error. When checking the logfile the file libraries/joomla/error/exception.php reported that allowed memor size was exhausted. I tried increasing it by adjusting the php.ini settings all the way up to 2 GB without resolving the problem. This is way more than Joomla should need.

The problem was that I had forgot to update the temp and log paths in Global settings to the ones on the new server. The path the site is running under can be found by the menu Help -> System info. Then I adjusted temp path and log path in Global settings and the problem was resolved.

If your site gives you error 500 internal server error, access your Joomla database using for example phpMyAdmin and delete all rows in the jos_session table.

Another solution if the problem is a corrupted database is to repair the database tables using phpMyAdmin.

In configuration.php, also try setting cache_handler=”file” instead of “memcache”.

Problem sending email on form submission in WordPress

Adding a form to your WordPress website is normally done by using a plugin for it, like Contact Form 7 for example. At some hosting providers, there can be a problem for the plugin to send emails to you when someone is posting through the form. To prevent spam through forms, many hosting providers disable the PHP mail function that is used in WordPress to send emails, causing for example form plugins not being able to send emails.

The solution is to set up WordPress to use SMTP, preferrably with authentication, to send the emails through a real email server. To do this you need a plugin like WP Mail SMTP. Set it up either with the hosting provider’s SMTP server or use the one you normally use for email.

PHP Parse error: syntax error, unexpected end of file in XXXXX.php

  • Check that you have spaces around curly braces, i.e. for example don’t use <?php}?> but instead use <?php } ?>
  • If your script has been running without problems on earlier versions of PHP but you are now running PHP 5.4 or later, replace all occurrences of <? with <?php

Joomla 3.4 too many redirects (303)

On a Joomla site currently in offline mode the front page gave us “too many redirects” error. It turned out the reason was the article connected to the home page menu item had been unpublished. By publishing the article the problem wsa solved.

Vivotek PT7137 rtsp stream to webpage using VLC plugin

One way of getting the video from Vivotek PT7137 to a webpage is by using the VLC plugin and connect the rtsp stream.

However, in current version of Chrome the VLC plugin is no longer supported. Instead it is suggested to use HTML5 to embed video, but rtsp is not supported in Chrome so it is kind of a dead end there for the moment. This solution works in for example Firefox.

In the webpage where you would like to add the stream:

<object classid=”clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921″ codebase=”http://download.videolan.org/pub/videolan/vlc/last/win32/axvlc.cab” id=”vlc”>
</object>
<embed type=”application/x-vlc-plugin” pluginspage=”http://www.videolan.org” autoplay=”yes” loop=”no” width=”600″ height=”340″ target=”rtsp://USERNAME:PASSWORD@IPADDRESS:554/live.sdp” />

Replace USERNAME, PASSWORD and IPADRESS with real values for your Vivotek PT7137 camera. It might be a good idea to create an account in the Vivotek PT7137 to use from the web as the username and password will be visible for anyone who inspects the webpage source code. That said, putting the root user account and password here would be considered stupid 🙂

Tip for Joomla users: If you include this code in a Joomla site, include {emailcloak=off} before the above, because the @-sign will trig Joomla email cloaking beliving it is an email address.