Description
HAHAH this blog rocks
My Links
*
*
*
*
*
|
SimpleTest vs PHPUnit
When it comes to Unit testing for PHP you have 2 choices. SimpleTest or PHPUnit, (yes I know there others, ...apparently). Both of those are really good at what they do, and I am not going to compare the various features, that has been done already.
What I will do is tell you my story and why I ultimately chose to use PHPUnit.
When I first started upgrading this site I had no unit tests at all, so I chose SimpleTest because it is really simple to use. You need to include a header file and your tests are good to go.
And this was the way it worked for a few months, I had +600 tests and I was very proud of myself.
But as time went by, I had to do more and more 'difficult' tests, like those using mocking, (admit it, when you start from scratch you always leave mocking to the end).
The other issue I have with SimpleTest is the fact that it has not been updated for well over a year, (at the time of writing this of course). PHPUnit on the other hand is updated all the time.
While I am the first to say that updates all the time is not necessarily a good sign, but no updates at all is also not very good, (and might be an issue as newer version of PHP are eventually released).
Also, phpunit has code coverage, this is a big plus for me :), it allows me to spot potential issues, (where I have no tests at all!), and also where I missed something.
So in short, I would say, go for PHPUnit, it is a little bit more of a learning curve at first, but in the long run you will have better tests that are easier to maintain.
|
Posted: 6:08 AM, 4/4/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Eclipse slow/broken DLTK index
I use Elcipse 4.2.x for developing my php websites.
But from time to time it re-indexes the workspace, sometimes it never end 're-indexing'.
An easy solution is to look for a folder in your workspace called "../workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2", (if you don't know where it is, just search for the folder "org.eclipse.dltk.core.index.sql.h2").
Make sure you close Eclipse, rename the folder "org.eclipse.dltk.core.index.sql.h2.old" and restart Eclipse.
The index will be re-created, but once it is done it should be faster.
|
Posted: 5:50 PM, 3/27/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Added instagram shortcode
When you find an image on instagram.com copy the url of the image and you can now add it in your own posts, simply type:
[instagram url=http://instagr.am/p/Ma3ji4OP2d/ size=large] or simply [instagram:http://instagr.am/p/Ma3ji4OP2d/], (you can also use the longer instagram.com url as well if that tickles your fancy).

The sizes available are , 'small', 'medium' or 'large', the default value is 'medium'.
Images are automatically linked, but you can add "linkback='false'" if you want to remove the link back.
|
Posted: 6:38 AM, 2/3/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Getting Premature end of script headers in Apache?
The other day I was working on a php script, and, for debugging purposes I placed it in a new folder.
Everything was working fine on the dev machines, but on the live server, it was not working at all.
I kept getting a "Error 500 - Internal server error", I even though there might be something wrong with my script, (you start to believe anything, no mater how improbable it might be :)), so I created a new simple script to rule out any code issues.
// simple code
But even that was not working at all... (so at least I knew it wasn't my code).
I knew that nothing had changed on the server, so it had to be something I just did. I created a new folder and I copied a new script into it.
In the end, the answer turned out to be something fairly straight forward, the directory I had created was created with 0777 permissions, (full permissions to do everything!).
My server itself is setup by default not to entertain scripts with such permissions, hence the 500 error.
Change the permission to 0755 and create a very simple script, (like the one above), if that does not help then your issue might be somewhere else...
Don't get me wrong, that might not always be the issue, (there are many other reasons for Internal server errors), but it is worth it to check the folder/file permissions before you start open heart surgery on your server.
|
Posted: 3:34 PM, 1/20/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Cosmetic changes
I made some small cosmetic changes to your manager section, the 'comments', 'pings' and the 'social' settings, (although I am tempted to move the social settings to its own plugin as this is really what it is...).
Also some of you that want to create a new weblog, (and if you are allowed to ), it is now easier and does not throw a bunch of errors as it used to .
As usual, I am slowly making my way through some of the cosmetic issues. I have a tentative deadline of June where I want it all done and I want to re-launch the site and there is still a lot of work to do.
If you see anything that is out of place, or you think I need to pay more attention to it, give me a shout...
|
Posted: 5:49 AM, 1/12/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Windows 'Zombie files' that will give you weird errors.
The other day I learned something new about the legacy windows file system. There are still some files/folder that you simply cannot create, files like "COM1, COM2, ..., or LPT1, LPT2, CON, AUX, PRN, and NUL", there might be more.
If you try and create/rename the files to one of those name, you will get a cryptic error like "the specified device name is invalid", "The file name already exists" on other programs like SVN you might even mess-up your repo if you try to force one of those name, (SVN will allow the name and windows will give you the finger if you try to update/clean up the file).
The beauty of those files is that it does not matter what the extension might be, in my case I was trying to create a php file, called "cron.php", but that file name is not allowed, (because of the 'cron').
I found a site that has a pseudo-regex you can use to check for valid files "/com\d(\..*)?, /lpt\d(\..*)?, /con(\..*)?, /aux(\..*)?, /prn(\..*)?, or /nul(\..*)?".
In the end it might not be a big issue, but it is something to bear in mind...
|
Posted: 5:49 AM, 1/3/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Happy new year!
Happy new year to all, I wish you all a blessed and wonderful 2013.
At the time of writing this entry I think there are only a few countries left around the world that are still in 2012, but for the most part we made it!
Personally, 2012 was a great year, full of happy memories, (with a few ups and downs), and I can only hope that 2013 will be even better.
For Journalhome, 2012 was not so great, we had a lot issues with the servers, not that many new features added and no new templates were added at all. But that does not mean that I was doing nothing, (I promise). I have stabilized the code a lot more and 2013 should see a lot more new features that should enhance your stay here. Unfortunatly the background work has to be done before all the 'pretty' stuff can be done.
But, in the end, we all made it, the end of the world came and went, so 2013 can only be better from now on!
|
Posted: 10h12, 1/1/2013 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Merry Christmas everybody!
Just a small note to wish you all a merry and blessed Christmas. I hope you have a great day with friends and family or even relaxing on your own.
If you are travelling, please have a safe journey and enjoy the trip.
I look forward to hearing all your holiday stories when you get back. Myself, I am spending the day with family and friends at home.
|
Posted: 06h04, 12/26/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Remove duplicate rows in MySQL using php
In some cases you might want to remove duplicate rows in a table, (to create a long forgotten UNIQUE index for example).
There are some tricks you can do using a script.
ALTER IGNORE TABLE yourtable ADD UNIQUE INDEX idx_name (some_col );
This does not always work because you might have an older version of MySQL and also, it could lock your table for ages...
An easier way is to use php to remove duplicates but first you need to do a few things
-
Backup your database.
-
Remove all codes that create the duplicate rows in the first place.
Create a script, "duplicates.php"
Create the query and fetch the rows
// connect $mysqli = new mysqli( ... ); // prepare the query $query = <<<EOT SELECT count( * ) cnt, link FROM yourtable GROUP BY some_col HAVING cnt >1 ORDER BY cnt DESC LIMIT 100 EOT;
Then loop around and remove all the duplicates, keep going around until you have nothing else to remove.
We only to 100 items at a time, this is to make sure we don't waste all our execution time getting data.
If the code times out, you can just start it again and again until you see the 'done' message.
for(;;) { // (re)prepare the query if( $result = $mysqli->query($query) ) { // fetch the rows while ($row = $result->fetch_assoc()) { $rows[] = $row; } // free the result. $result->free(); } // delete all the values foreach( $rows as $row ) { // delete one row less than the total number of rows. $query2 = "DELETE FROM yourtable WHERE somecol='{$row['somecol']}' LIMIT " .((int)$row['cnt'] - 1)); $mysqli->query($query2 ); } } // clean up ... echo 'Done!';
If the code times out then simply re-run it, you will not delete more that duplicates and you will not lock the table, (well not too much).
|
Posted: 5:32 PM, 12/3/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Does session_start() slow my script?
The short answer is , yes, no, and maybe :).
By default sessions are saved in a file in your temp directory, (check out the value session.save_handler and session.save_path in your php.ini file).
This works great for most small to medium site, when a user visits your site a session file is created and/or the data is updated.
The problem comes when the site gets busier and busier, more and more users are trying to create sessions files. The OS is trying to read/write/delete hundreds of files. And in any case, the OS only allows access to one file at a time, so they run sequentially, not in parallel (*).
So, what is the solution?
-
Don't use sessions unless you have to, calling session_start() every time will cause issues, (check out session.auto_start).
-
On really big sites, use database, (or something similar), to manage your sessions.
-
Even if you think you need sessions, think again...
-
With social sites like OpenID, LinkedIn, Facebook and so on, sessions are used a lot, so don't think you can create a site with no sessions ...
(*) Most of the time you want it to run sequentially, because if both scripts update the $_SESSION data it is not possible to get/set the data to be shared by both, (Well, not without using a database or something similar).
You can handle sessions yourself using session_set_save_handler.
|
Posted: 9:15 PM, 11/28/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Moved to a new server
I made the decision to move to a new server this week, the old one was just too small, (by small I mean not enough memory!).
I could have spent some time trying to optimise the scripts and database but at the rate we are growing I was fighting a loosing battle. I also think there was something seriously wrong with the old server, but my host was not very helpful in that matter.
The down side of it all is the monthly cost of such a server, currently this is coming straight out of my pocket and it will not be long before it start hurting the pocket :). I don't mind doing it a bit longer, I enjoy the work, it is fun... but expensive.
I am looking for a template developer to re-design the site, (this one is 7 years old already!), this will probably cost a lot of money, but with a bit of luck I will find someone who can do it for free. I might even throw in some free advertising or something. I think with the right design we will get a lot of new blogers.
I also need to design a new 'mobile' site as more and more of our visitors are mobile users.
|
Posted: 6:18 PM, 11/28/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Add cache control to dynamic content in php
Cache control enables you to tell the browser if the contents have changed since the last time they visited.
If nothing changed, then the browser will use whatever data it has in cache and that will save your users a few milliseconds, (and they will a cheer loudly).
For a website like this one, it is important because we have many pages that will no longer change, (archive pages for example, old pages from users that will never return).
First we need to set the cache limiter, the default is to have 'nocache'so you might want to change the value to something like 'public' or 'private'. Read up about the various options before you set it.
// make the data fairly private // start the session.
Now you can go ahead and create your page as you would normally. Don't echo anything out to the browser, rather save it all to a single string.
// create the page $output = get_my_dynamic_page(); // get the time the page was last modified. // as this is a dynamic page we need to know when last the content changed. $modified = get_last_modified(); // then we need to create a tag for this, (we will use it later). // create the etag using the output $eTag = "'".md5($output)."'"; // send it to the browser. // add the date $date = gmdate('D, d M Y H:i:s', $last_modified_time); // send the tag+header header('Last-Modified: '.$date.' GMT'); // first we check the check if the etag matches. if( isset($_SERVER['HTTP_IF_NONE_MATCH']) && $eTag == $_SERVER['HTTP_IF_NONE_MATCH']) { // then we check that the modified time matches our own time. if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time) { // tell the browser that nothing changed. header("HTTP/1.0 304 Not Modified"); // no need to go any further. return; }// modified time match or no modified time was given. }// etag match // Tell the browser which size the content // if we made it here, echo to the browser. echo $output;
The code above should be self explanatory,
First, you create your page based on whatever data you might have, be sure to have a date of some sort so you know when it was changed.
Next you create a unique kind id or code to identify if the page that the browser has on record matches the one you have just created.
Finally, if everything matches, then you are golden and you can tell the browser that everything matches.
Be warned, caching is not the magic bullet you think it is, it will not save you a major amount of time, and you need to support cache for your css/js scripts as well as images.
Also, there are many tools going around telling you what the response headers might be, some of them will keep returning 200 because this is the cache response.
I found that Firebug does return the true response header, (what php developer doesn't use Firebug anyway?)
One final word, if you are playing with
|
Posted: 12:55 PM, 11/22/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP
I was looking at an issue this morning where the code was timeout in certain situation.
While I could understand the reason for the timeout I was wondering if my code could catch if/when it happens.
Using php5 I can easily test if the error is caught.
// the function that will handle the shutdown function shutdown() { if($a==null) echo "No errors"; else } // Register for shutdown, called when there are no errors and/or there is a timeout issue, (or any fatal issues). // change to 1, default is 30 seconds. // do nothing for longer than 1 second.
I then went one step further and logged the error to the database without any problems.
So it seems that the timeout does allow you to catch the execution timeout then do some work.
NB: If you get "No errors" it means that changing the timeout did not work. This is not impossible as certain hosts do not allow certain ini_set values.
|
Posted: 1:56 PM, 11/21/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Automatically close comments after ... days
Hi,
I added a new option to close comments after a certain amount of days.

Go to your weblog and select > Comment settings, toward the bottom you can now select to close your comments after xyz days.
Because of the number of blogs we currently have I had to choose a default behavior, so now all comments will close after 14 days of been published.
You can of course change those settings.
Let me know if you have any issues.
Thanks
|
Posted: 9:06 AM, 11/8/2012 by JournalHome.com |
Comments (1) | Link |
|
Share and enjoy
New update happening
Hi all,
I just did a major update, (version 3.38 if you must know). It gets rid of the last of the 'bad' code that was left behind from the original developers.
It has been quite an uphill battle to keep the site up and running while getting rid of all that legacy code.
I can now proceed with the 'look' of the site. I have 3 major projects and 1 ongoing one, that I can now concentrate on
-
Create a new template for this site, the current look of the site is 7 years old. It has to go.
-
Create a 'mobile' template for mobile visitors.
-
Add new templates, (I still want to use the hundreds of free-to-use that are lying around).
-
Add more features to the current blogs.
Unfortunately #3 is probably take the longest to implement.
I'll spend the week-end pouring over the logs to see any errors reported, but if you see something wrong, just drop me a note and I will update it asap.
|
Posted: 6:05 PM, 11/3/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Database issues/down [resolved]
Hi,
Yesterday we had a small issue with the database, (the cached data to be exact).
This caused the site to missbehave for over an hour as it could not cache any data, but this has now been resolved. For about an hour after that, while the cache was been rebuilt, the site was running a bit slow.
All should be back to normal, but please let me know if you can still see an issue.
Sorry about that,
FFMG
|
Posted: 5:56 AM, 10/20/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Login to Journalhome using foursquare
I just added a new way or login-in or creating an account, if you have an foursquare.com account then you can simply link to it by pressing the “Connect to foursquare” button. If you already have an account here, fear not, just log-in as usual and then click on the button and, (after you authorise Journalhome.com), we will link both accounts and you will be good to go. So you can now login via, Twitter, Facebook, Foursquare and Linkedin. As always, if you have any issues, please let me know.
|
Posted: 10:36 AM, 7/21/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Updated template "Midnight Snack"
I updated the Midnight Snack template. This is a very simple template with no plugins and no calendars.
Have a look at the example site and tell me what you think 
|
Posted: 4:49 AM, 4/29/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
Updated template "Infinite Destiny"

I updated the Infinite Destiny template. It now handles the wider comments box as well as the wider plugins.
Have a look at the example site and tell me what you think 
|
Posted: 6:57 PM, 4/24/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
New 'Contact-us' page.
The other day some spammer sent me an an email complaining that his/her account was blocked and that there was no way of 'appealing' the block, in fact he complained that there was no contact page at all.
I have to admit, I am embarrassed to say, never even though of it, users have been able to contact me via messaging, but this is not possible to contact us if your account is blocked, or even if you are just wanting to ask a question.
So you can now contact-us directly if you have any queries/questions and we'll get back to you as soon as possible.
|
Posted: 5:25 AM, 4/14/2012 by JournalHome.com |
Comments (0) | Link |
|
Share and enjoy
|