Delete files older than x minutes (Linux)

26 Oct

Up until recently, I’d never needed to delete files automatically that were less than a day old. There is a useful switch you can pass to find that lets you return files that haven’t been changed in x minutes, and that can be used for temporary file cleanups or whatever.

Here it is:

find /tmp/foo/ -type f -cmin +180 | xargs /bin/rm -rf

That will return any files inside /tmp/foo/ that haven’t been changed in at least 3 hours.

PHP post_max_size limit for large files

30 Aug

This just caught me out.

If you are dealing with large file uploads with PHP, be warned that PHP uses an integer for the upload_max_filesize and post_max_size config variables. That means, you cannot set those values higher than 2147483647 bytes. Trying to use 2048M for example, will result in an error like this:

Aug 29 21:12:48 svr php-cgi: PHP Warning:  Unknown: POST Content-Length of 41 bytes exceeds the limit of -2147483648 bytes in Unknown on line 0

Whenever something is posted to the server (even simple name-value pairs). This will happen on both 32bit and 64bit machines.

This is clearly stated in the manual, but I totally missed it!

Duplicate sub-menu in plugin menu (WordPress)

2 Jun

I just had an issue pop up while creating a WordPress Plugin that uses a custom, top-level administration menu. If I created a top-level menu called “Foo”, a submenu would be created beneath it that had the same link and title. A picture describes the issue better:
Menu Example 1

The code used to generate the broken example above, is:

add_menu_page(__('Foo'), __('Foo'), 'manage_options', 'foo.php');
add_submenu_page('foo.php', __('Bar'), __('Bar'), 'manage_options', 'bar.php', 'bar');

That clearly sucks, and isn’t what I wanted in this situation. What you need to do instead is change the add_submenu_page function to:

add_submenu_page('foo.php', __('Bar'), __('Bar'), 'manage_options', 'foo.php', 'bar');

* Note the second-to-last param now matches the one in add_menu_page()

That clears up the issue nicely. For what it’s worth, this is clearly documented in the WordPress Codex but I, and apparently a lot of other people, missed it.

I have no title for this post

15 Feb

This is just a note to the three people who used to read this blog. I haven’t updated it in forever because I don’t have the time to write interesting articles at the moment, and I have never been big on the random thought kind of blog.

If you want to know what I’m up to and chat to me follow me on twitter – http://www.twitter.com/m3rls.

I can’t promise anything but I’m hoping to devote a little bit of time to this thing sooner rather than later, but be warned, anything I do post is going to be nerdy.

Thanks, hope you’re all well!

Dump stored routines only with mysqldump

26 Aug

I needed to dump a bunch of stored routines (namely triggers, procedures and functions) from a mysql database, and I didn’t want any of the other junk that mysqldump normlly outputs.

After a bit of searching and fiddling, this is the command I ended up using:

mysqldump filefactory --skip-opt --no-create-info --no-data --routines --triggers -S /data/mysql_5_databases/mysql.sock --password

Newline after -S added by me. Remove it if copying/pasting.

You probably won’t need to specify the socket file and you may not need a password. Just amend the command as necessary to suit your needs.

Enjoy.