Write your own independent background process using PHP

Sometimes we want a PHP script to run all day and all night as a background process, not directly under control of the user, but as a system like daemon. This is surprisingly easy thing to do with a PHP Script.

I have written a simple example how to do this using PHP. It should get you up to speed quickly, and could be used as a framework to write your own more sophisticated background processes.

You can find it here https://evadinggrid.wordpress.com/php-cli-command-line-scriting/how-to-with-php-write-a-background-daemon-server-process/


Adding a custom “right-click” menu – KDE Service Menu

It is very easy to add a custom menu in KDE. You do not need real programmer skills or a degree in computer science. I will explain by example here how to add a menu to convert a youtube *.flv file to a regular *.mpeg.

First off lets find where KDE hides these service menus. Open up dolphin and open the
View menu. Look down and select Show Hidden Files. Then find the directory folder called .KDE

Now inside .KDE is a directory folder to store all the service menu entries. They are a special type of *.desktop file, whose contents look similar to a tiny *.ini file. Use the Find Files Tool to search for *.desktop, I say this because KDE changes over time, but most annoying is that distro’s play around moving stuff.

Look for something like /share/kde4/services

Ignore stuff related to /share/apps/ , but do note that KDE uses *.desktop files for things besides service menus.

Ok, if your like me, you will create a quick link to this hidden directory folder, to some where like your Projects directory, to avoid this hidden files problem.

Ok, well that is the worst bit over, now to the actual desktop file.

The actual desktop file is quiet self explanatory, it is in 4 sections, and gives two menu entries. If you copy paste this example, you can probably edit it to customize to do whatever you want. I could have given a 4 line example, but within seconds most people would want something more useful with sub-menu options.

If you copy paste this into /share/kde4/services and then right-click on a *flv file, and look under the Actions menu you should be able to find a sub-menu called Convert FLV video and then two menu options, to choose between modern rectangular Wide Screen 16:9 or old fashioned square TV 4:3.

Take note, this menu will only appear if you click on an *.flv file, it will never appear on any other mimetype.

[Desktop Entry]
X-KDE-Submenu=Convert FLV video

[Desktop Action ConvertToMPEGwide]
Name=Convert flv video into 16:9 PAL-DVD mpg
Exec=ffmpeg -i %u -target pal-dvd -ac 2 -r 25.000 -s 720x576 -aspect 16:9 "%u.PAL-DVD.16:9.Q-defaults.mpg"

[Desktop Action ConvertToMPEGsquare]
Name=Convert flv video into 4:3 PAL-DVD mpg
Exec=ffmpeg -i %u -target pal-dvd -ac 2 -r 25.000 -s 720x576 -aspect 4:3 "%u.PAL-DVD.4:3.Q-defaults.mpg"

I think the only thing that needs a word of explanation is the %u if the Exec line – which when run will insert the file name into the Exec command line. The Exec line, is where the real work is done, it is where the command is invoked.

Of course if you are American, you would also want to change from PAL to what America uses, which is NTSC standard for TV and DVD stuff…

These *.desktop files have other uses, obviously you most often see them as shortcuts on your desktop. This is why I suggested you used the Find Files tool, to see where the critters hide. Take a little time, and read some of them, and you will rapidly clue in as to how they work and how it all fits together.