Archive for the ‘PHP’ Category
ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13)
When running PHP5 under Ubuntu, every ~100 times you call session_start() the following error is thrown:
ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in ...
By default, session data is stored in /var/lib/php5 which has its permissions set to only allow data to be deleted by it’s owner (and root). It’s like this because there is a cron script that periodically clears the session data. To prevent PHP from also trying to do this, switch off the session garbage collection in php.ini (/etc/php5/apache2/php.ini) with the following:
session.gc_probability = 0It is quite likely to be set to 1 by default. Save changes and restart apache.
sudo /etc/init.d/apache2 restart
Shorten URLs and post to Twitter with PHP and cURL
I recently had the task of automatically “tweeting” when a new article was posted to one of the websites I had built, it turns out to be a pretty simple operation thanks to both Twitter and Bit.ly providing a straight forward API. An account with Bit.ly does have to be opened to obtain an API key.
I decided to use the built-in cURL functionality of PHP for interacting with the APIs. This code uses some of the JSON functions introduced in PHP 5.2.0 so a recent install of PHP is required as the Bit.ly API responds with a JSON string. On to the code…
(more…)
Overview of open tickets across multiple trac environments
I’ve recently started using Trac internally for managing the ever growing list of projects that I have built and am responsible for maintaining. There is currently no feature within Trac for displaying a list of all the environments and how many open tickets each one has, and I’m guessing this is down to the fact that each environment has it’s own SQLite database.
However, browsing the root of the Trac install does give a list of all the available environments, and there are RSS feeds available for any of the reports that have been created. So I wrote a quick script to pull information from both of these resources and display a list of all available environments and how many open tickets each one has. (more…)
Recolouring images with PHP
About a year ago I was working on a project where one of its features allowed the user to upload an image, select a colour on the image with a colour picker tool, then select from a group of colours to replace the picked colour with. I had a somewhat stable build running where it simply replaced the hue of the picked colour – Introducing saturation and value changes invoked a number of ‘random’ glitches and odd colour effects. This feature was subsequently dropped from the project due to it costing too much to continue developing.
Skip forward about a year and I find this script knocking around on a back-up disc, so I decide to put some more development time in purely for my own satisfaction of enhancing it. I have made it work to a nearly passable level, it works nice on images with isolated high contrasting colours. I created a function to create a tiled pop-arty graphic from an inputted image too just for fun. For example, input this and it will spit out this. There is plenty of room for improvement: You can’t convert colours to or from white/black and it replaces all instances of a colour, not a flood-fill effect. So, on to the code… (more…)
You are currently browsing the archives for the PHP category.
