ASP vs PHP for long tasks
Yesterday, I got a good taste of what it’s like for a programming language on a web server to be handed a massive task to complete.
I was tasked with automating emails to subscribers of a vacancies alert service. The script as it stood was run manually once a day just before the end of work, and this script (written in PHP) would query the SQL server for details of subscribers and their preferences, and then compile individual emails and send them off. With hundreds of subscribers, this is quite a task. Nevertheless, the script took around 4 minutes at the most.
The preference was to move this script from the desktop to the server and automate it with a cron job. However, the database it interacts with is stored in MSSQL, and the way that the system is set up does not allow PHP access to MSSQL; only ASP.
I decided to re-write the whole script in ASP, upload it, test it, and then create a cron job to run it daily. With a few bumps and scrapes, I managed to port the script, but when I started to test it, the script timed out. OK, I thought: the automatic timeout is 90 seconds, which is not enough for this script. I increased it to four minutes (the length of time the PHP equivalent took), but it still timed out. Then I went to 6 minutes and the same happened. It was then that I realised that until timing out, the script would also bring down the whole site. This was unacceptable, and therefore we decided to revert to a desktop script, albeit automated with Scheduled Tasks in Windows.
This brings me neatly to the conclusion: ASP is much slower than PHP for running equivalent scripts, and its inefficiencies really showed up in this test and taught me a valuable lesson about using web scripts for very long tasks.