Run Scripts in Separate Threads in PHP

I’ve been working on a new project over the past few weeks and one of the requirements of the system was to update a number of records in the database based off the data stored in a large quantity of XML files that would be stored on an external CDN. While initially this didn’t seem a problem, once the number of records grew that were required to be updated it became obvious that doing the updates sequentially wasn’t going to work, and as I didn’t have the required extensions to use pcntl-fork I had to come up with another way to launch multiple updates simulatenously, which turned out to be much simpler than I had thought but took a bit of searching to find:

<?php
	exec("nohup /usr/local/bin/php -f /path/to/script/file.php parameterValue &gt; /dev/null &amp;");
?>

This will execute the PHP script stored in file.php in its own thread but the PHP script calling it will not have to wait on it finishing execution as it would be if you called the script without the nohup and > /dev/null &. This solution will only work on *nix systems as opposed to Windows, but I imagine there is probably a way to do it in Windows too. The downside to this is that you will not be able to get any return value from the script, therefore it is only of any use if you need to run a task that does not require the calling file to get the results back. You can however pass data to the script as I have done in the example above, the value “parameterValue” would be available to file.php via $argv[1], for example:

<?php

	/* -- file.php -- */
	echo 'The value '.$argv[1].' was passed to me via a CLI command.';

?>
Posted in Programming, Web Development at September 6th, 2011. No Comments.

Google+

I finally got myself an invite to the new Google+ network, and it is awesome! If you haven’t heard of it, it’s essentially Google’s attempt to combat Facebook; and to be frank, if the beta is anything to go by it’s going to be a Fatality.

As you can see in the two screenshots below, the Stream is the equivalent to Facebook’s Wall, and looks and works in a similar way (I think at this point doing anything radically different wouldn’t be a smart move on their part). It contains people’s latest activity such as photo uploads, people being tagged in photos, messages etc. The key feature in this which a lot of people seem excited about, is the ability to select only certain “circles” to share information with (see the third screenshot below).

The other big thing that is causing some hype is the “Hangouts”, these are essentially chat rooms which you can start with members of your circles but with the ability to utilise both audio and video. I’ve unfortunately not been able to try this out as of yet, but if the quality of this feature is up to the same standard that the rest of the system is, it will be very impressive. In terms of problems I’ve surprisingly not ran into any yet, for a product that hasn’t even been finished yet I’d say that is quite a promising sign.

HTML Engine Limitations in Outlook 2007

It’s been a while since I’ve posted on here, I have been incredibly busy as of late but today at work I came across something I thought I would share as it may save some people quite a lot of trouble. I was helping a colleague produce a HTML driven e-mail which requires some absolute positioning, tested it in IE – no problems, so naturally I assumed it would be no issue in Outlook as Outlook uses IE’s engine to render HTML – wrong.

In Outlook 2007 Microsoft have found it a good idea to use Microsoft Word to render the HTML as opposed to a web browser, who’s purpose is to render HTML. As a result of this a lot of CSS support has been cut (including positioning).  So before you start doing any coding for HTML based e-mails that will be read via Outlook 2007 I would strongly recommend taking a look at the Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 article on MSDN as it contains a full reference as to what is now supported.

I also came across a very handy eBook by John Doub which contains some tips and tricks to work around the newly introduced limitations, Click Here to Download HTML e-Mail Rendering in Outlook 2007 by John Doub.

They say sometimes you have to take a step backwards to move forward, but this is one giant leap backwards as far as I’m concerned; hopefully Microsoft will bring back the HTML support that Outlook was once well known for.

Posted in Programming, Software, Technology, Web Design, Web Development at September 14th, 2010. No Comments.

Winner of the O’Reilly Academic Prize Scheme 2010

This year my university decided to enter all the third year BSc computing students into a competition held by O’Reilly for the best and most original dissertation; my entry was of course phpAnalyzer. A couple of days ago along side the results of my degree, I got my prize in the mail as well as a little certificate – definitely a good way to end three years of higher education!

In addition to getting good results and winning the contest held by O’Reilly I also got a new job as a software developer, so now when I’m not at home programming, I’m at work programming! It’s been a bit tough making the transition from the life of a student to doing five full days of work every week but I can’t complain as I am doing something I love and I am working with nice people who are helping me get to grips with their way of doing things. As a result of starting my new job one of my new projects has been slowed down a bit, as well as the development of EDK (which is now nearly finished) but I’m slowly picking the pace back up as I get adjusted to working life. My new project is another Xbox LIVE game which I will also make available on the PC, I have managed to get quite a lot of people on board so far; at the moment the team consists of:

  • One developer (myself as you can imagine)
  • One artist
  • Two graphics designers
  • Five level designers
  • Two audio engineers

The only thing really missing at the moment is someone to come up with a storyline, but if I fail to find anyone to come up with a plot I’ll just throw in more blood and violence – that is a suitable replacement for a good story isn’t it?

phpAnalyzer Goes Live!

phpAnalyzerAfter many months of analysis, research, design, development and testing I have decided to open phpAnalyzer to the public. Up until this point I have been very secretive about the system as I produced it in partial fulfilment of my BSc and didn’t want anyone with more resources and time to be able to spring up a similar system overnight that voids the usefulness of my own; now however I can launch it and I hope that it will be of use to people and meet the goals it was originally designed to conquer.

Check out phpAnalyzer at: http://www.phpanalyzer.co.uk/

What is phpAnalyzer?

phpAnalyzer allows users to upload a script to the system, at which point it will scan the script for bad PHP development practise; once the file has been fully scanned a report will be displayed to the user which indicates what they need to revise and display possible solutions to the problems, which in most cases will contain links to the appropriate pages in the online PHP manual which will aid the user in implementing the updated and correct methods and or global objects.

Who is phpAnalyzer aimed at?

It is primarily aimed towards students / people learning PHP as with an ever growing number of students and freelance developers turning to online resources it is important that a tool be available that will allow the developer-to-be to ensure what they are reading about is indeed the way they should be tackling a given problem.

Posted in Software, Technology, Web Design, Web Development at May 25th, 2010. 2 Comments.