Accelerating PHP with the Alternative PHP Cache

I decided to install the open source Alternative PHP Cache on this server in order to improve performance. Interesting exercise. This server runs Debian Linux, and there are several ways to install APC:

1. Install the official package with apt-get install php-apc or similar

2. Install with the PHP Extension Community Library which goes something like:

apt-get install apache2
apt-get install libapache2-mod-php5
apt-get install php-pear
apt-get install php5-dev
apt-get install make
apt-get install apache2-prefork-dev
pecl install apc

The advantage over (1) is that you get the latest stable build, version 3.1.6, instead of the Debian package which is 3.0.19

3. Download the source and do something like this to install.

I started with option (2) though I came to regret it. The first problem is that the pecl installer will build with your currently-installed Apache, and if you later upgrade Apache it might break. Sticking with the official package is safer, even though it is very out of date.

I could live with the idea of re-installing APC every time Apache was updated if necessary, but I had another problem. I was up and running with APC 3.1.6 and pleased with the results, until after a while everything stopped working and my blog became a screen full of messages saying “Unable to allocate memory for pool”.

It looks like this bug, which was said to be fixed in version 3.1.5, but if you look to the end of the comments there is one from today with the same issue, and no suggestions about how to fix it.

The ancient version, on the other hand, has performed perfectly so far.

Another point of interest: I found it challenging to discover the best settings for APC. By default the install does no more than to enable the extension; but the default setting is unlikely to be the best one. The documentation tells you what each setting does, but not how to choose the best values for those settings. Should the cache be the default 32MB, or something much greater? Another thing to note: if you compile with MMAP support, which is the default, the value of apc.shm_segments is ignored, and the value in apc.shm_size will solely determine the size of the cache.

I found this Moodle article on installing APC in Windows helpful. What you do is first to find the file apc.php which the install put somewhere like /usr/share/doc/php-apc – in my case it was also compressed -  and put this on your website, preferably in a password-protected folder. This tells you the status of the cache. The aim is to have the cache just big enough that it does not become full and highly fragmented. Here is what I get after a short run with 128MB, which may be a little too much:

image

Another tip is to set apc.stat to 0. This means APC will not check for changes in PHP files since they were last compiled and cached. The downside is that every time you change a file you have to restart the web server; but the benefit is better performance, which is the goal after all.

Silverlight native extensions allow deep Windows 7 integration, but forget cross-platform

Microsoft has released Native Extensions for Silverlight, a set of libraries which enable access to Windows 7 features including taskbar Jump Lists; access to attached devices including webcams, cameras and phones; the sensor API for accelerometer support; and even the ability to intercept Windows messages. The ability to intercept Windows messages allows lots of interesting hacks as veteran Visual Basic developers will recall; it was one of the tricks used to overcome limitations in early versions of VB.

The native extensions are only available to out of browser applications running outside the sandbox; the user must consent to trust such applications. Silverlight 4 already had the ability to use COM automation. These new extensions simply build on this existing feature, providing COM automation wrappers for these Windows 7 APIs.

What this means though is that Silverlight developers can create applications that integrate deeply with the Windows 7 desktop and local hardware.

Another way of looking at this is that the subset of Windows applications that can be implemented in Silverlight rather than the full .NET Framework has now increased. It lends some support to the theory which I considered here, that a future version of Silverlight will be the application platform for the Windows 8 app store and for mobile devices running Windows 8. This is speculation though; Microsoft has not said much publicly on the subject. Silverlight is well suited to an app store since installation is easy, updates are near-automatic, and apps are isolated from the rest of the operating system.

The native extensions are Windows 7 only. Forget the Mac, these things do not even work on Windows XP. They only apply to trusted out of browser applications though. Silverlight running in the browser still has similar features on Windows and Mac.

Amazon’s Elastic Beanstalk auto-scales your cloud application

Amazon has announced Elastic Beanstalk, which lets you deploy an application to Amazon’s EC2 (Elastic Compute Cloud) and have it scale up or down, by launching or terminating server instances, according to demand. There is no additional cost for using Elastic Beanstalk; you are charged for the instances you use.

Here is a dialog from the control console that says a lot about how the new service works:

image

As you can see, you can specify both a minimum and a maximum instance count, where the number is between 1 and 10,000. You can also control the “Trigger”, the metric that makes Elastic Beanstalk create or terminate instances.

Currently Elastic Beanstalk is for Java applications running on the Apache Tomcat application server, on a standard Amazon Linux virtual machine. However, the following comment in the FAQ indicates that Amazon is investigating other platforms:

Yes. Elastic Beanstalk is designed so that it can be extended to support multiple development stacks and programming languages in the future.

The innovation here is not so much in the technology, which stiches together a number of existing services, but rather in how easy and cheap it is to get started. The cost of entry is almost nothing; in fact, Amazon says you can run Elastic Beanstalk on its free usage tier, for a low-use application. Even I you expect it to remain low-use Elastic Beanstalk provides some other useful features like health monitoring.

It seems to me that this new service is cloud deployment as it should be: removing the administrative burden of scaling your application according to demand. Other platforms like Google App Engine also do this, but with more restrictions on how you design your application. Platforms like Microsoft Windows Azure let you scale your application, but you have to log into the console and spin instances up or down yourself.

One final observation: despite considerable unhappiness in the Java community about the way Oracle is managing the platform, there are still excellent reasons to use it, and Amazon has just provided one more.

Fixing slow access to SharePoint mapped drives in Windows 7

I’ve heard recently from a couple of people who found that accessing SharePoint folders via mapped drives in Windows Explorer had suddenly become very slow – even taking several minutes to open a folder. This is in Windows 7, but the same might (or might not) apply to other versions of Windows.

SharePoint folders in Windows Explorer use WebDAV (Web-based Distributed Authoring and Versioning) under the hood, so although it looks like just another shared drive it is actually using HTTP calls to list the files. It is useful if you are out and about, because you can get at documents on your internal network over the internet, using SSL to secure the connection.

The fix that has worked in both cases is a mysterious one. You open Internet Explorer (even if you use a different browser), go to Tools – Internet Options – Connections, click LAN settings, and uncheck Automatically detect settings.

image

I am not sure why this works but presumably with this option checked there is some sort of useless auto-detection going on which times out and then repeats.

No promises; but making this change can dramatically improve performance.

Appcelerator acquires Aptana

Appcelerator, a company whose main product is a cross-platform desktop and mobile toolkit called Titanium, has acquired Aptana, whose Aptana Studio 2 is probably the best IDE for JavaScript application development, and which also supports Ruby on Rails, PHP, Python, and Adobe AIR.

It makes sense, in that Titanium uses JavaScript as the primary language for the application logic and UI.

image

Appcelerator is already doing well from the current surge of interest in mobile apps, offering an obvious solution to developers endeavouring to support both Apple iOS and Google Android with a single code base. Aptana looks a good acquisition; but the news may not be so welcome to those who rely on Aptana Studio for Adobe AIR; I imagine Appcelerator may see this as a competing platform. Then again, most AIR developers use the Flash IDE or Flash Builder so it is unlikely to have a huge impact even if AIR support is dropped (I do not know what the plans are in this respect).

The server-side technologies like PHP and Ruby are a better fit, since many mobile apps have a server component.

Update: in the webcast about the acquisition, Appcelerator CEO Jeff Haynie said “There’s quite a few questions around Aptana as it relates to Adobe and ColdFusion; I don’t think we can say anything about that.”

The company is expecting to release a joint Aptana Studio/Appcelerator Titanium beta in March 2011. The initial release will not include a visual designer, though this is planned for some future release.

Talk of Windows 8 on an smartphone shows Microsoft’s mobile confusion

During a conference call to discuss Intel’s latest financials, CEO Paul Otellini raised the possibility of putting the full Windows OS onto a smartphone, running a low power Intel SoC (System on Chip). The matter came up with Otellini was asked about the impact of Windows on ARM, announced at CES earlier this month:

The plus for Intel is that as they unify their operating systems we now have the ability for the first time: one, to have a designed-from-scratch, touch-enabled operating system for tablets that runs on Intel that we don’t have today. And secondly, we have the ability to put our lowest-power Intel processors running Windows 8 – or ‘next-generation Windows’ – into phones, because it’s the same OS stack. And I look at that as an upside opportunity for us.

The reasoning seems to be: if Windows 8 is designed to run well on mobile devices with ARM, it will also run well on mobile devices with an Intel SoC, which will let us put it on phones.

Note the point he highlighted: Microsoft unifying its operating systems. No more full Windows vs Windows CE; one OS from mobile to desktop.

Although that sounds compelling, the snag is that Windows is not well suited to low-power mobile devices, which is why Windows CE was invented in the first place. Microsoft can fix this to some extent by fixing the things that make it unsuitable, but it carries a heavy compatibility burden.

It also throws up the question: just what are Microsoft’s long-term plans for Windows Phone 7, which is built on Windows CE, has its own GUI mostly written in native code, and a development platform based on .NET – Silverlight and XNA – plus a native code SDK that only mobile operators and device manufacturers get to use?

At CES Microsoft Steven Sinofsky sort-of denied that Windows will encroach on Windows Phone 7 territory. “Windows Phone 7 is uniquely focused on the small form factor that Windows doesn’t focus on,” he said.

Nevertheless, the company’s decision not to use the Windows Phone 7 OS for tablets may make that inevitable. What is the difference between a smartphone and a small tablet? Does Microsoft expect developers to write apps designed for Windows on a small tablet and then rewrite them for Windows Phone 7 using Silverlight?

It does not make sense; and despite the Windows Phone 7 promotion included in CEO Steve Ballmer’s CES keynote, I was left wondering whether Microsoft’s new mobile OS really has a future.

That said, Silverlight abstracts the OS, so in principle Microsoft could use it to form a consistent mobile development platform irrespective of whether the underlying OS is Windows CE or full Windows. I am not getting that sense from the company though, and I’d expect the primary Windows SDK to remain based on C++.

I am struggling to understand how Microsoft expects this to work. App compatibility is the obvious benefit of full Windows; but two big issues are that most Windows apps are not touch-friendly and are not designed for small screens. Putting Windows on a tablet with a decent screen size and the dreaded stylus works to some extent, but will never compete with Apple’s iPad for usability. On smaller screens most existing apps will not work properly; and if Windows on small devices sprouts a completely new touch-friendly GUI, or borrows the one from Windows Phone 7, then app compatibility with desktop Windows will be limited.

It feels as if Microsoft’s Windows team is saying one thing, the Windows Phone 7 and developer teams saying another, and partners like Intel saying yet another. Windows Phone 7 was meant to be the thing that made belated sense of Microsoft’s mobile strategy, but even that now looks doubtful for the reasons stated above.

Microsoft is still a long way from having a coherent strategy for mobile devices, and that lack is damaging the company and helping Apple and Google to establish their competing operating systems.

Update: Mary-Jo Foley writes about Microsoft “Jupiter” which is a rumoured new user interface and application model designed for Windows 8 and its app store:

Jupiter is going to be a new user interface (UI) library for Windows, built alongside Windows 8. It will be a thin XAML/UI layer on top of Windows application programming interfaces and frameworks for subsystems like graphics, text and input. The idea is Jupiter will bring support for smoother and more fluid animation, rich typography, and new media capabilities to Windows 8 devices.

Is Jupiter a .Net technology, or XAML adapted for native code, or both? Is it one and the same as, say, Silverlight 6? That is not stated, though Senior VP Soma Somasegar helpfully (or not) said that:

some of the information in this post is not right and out of date, not reflecting Microsoft’s current thinking.

That seems to tacitly confirm that it fairly represents Microsoft’s thinking at some time in the not-too-distant past.

It would make sense to me if Microsoft used Silverlight to unify its application platform as mentioned above, and combining the XAML presentation layer with native code could address performance and memory usage concerns with .NET. This is the kind of news that would really give confidence to Silverlight developers, rather than the damage limitation PR that Microsoft has put out since PDC late last year.

On the other hand, I believe Somasegar when he says the information is out of date, so for the time being it is just another dose of uncertainty.

Adobe AIR is user-hostile compared to native apps says BankSimple CTO

Alex Payne, CTO at BankSimple, has written an analysis of Adobe AIR from the user’s perspective. The scenario: his team was looking for a an alternative to Campfire for group chat, and selected HipChat. They liked the features of HipChat, but not the desktop app, which is built using Adobe AIR:

My team experienced a number of the usual problems one has with AIR applications: lousy performance, odd interface bugs, key combinations and UI elements that didn’t conform to our operating system. AIR apps exist in an uncanny valley between a web application and a desktop application, and the result is unsettling and annoying. Pretty soon, we were itching to go back to Campfire (via the native Mac client Propane), even though HipChat has better features and the promise of improved reliability.

Payne investigated further and came to the conclusion that users prefer native apps; and that cross-platform toolkits are for the benefit of software companies not users. Echoes of Steve Jobs’ Thoughts on Flash:

Flash is a cross platform development tool. It is not Adobe’s goal to help developers write the best iPhone, iPod and iPad apps. It is their goal to help developers write cross platform apps.

And lest you think this is bad for AIR but good for Java, note that Payne adds:

For anyone who used a computer in the 1990s, AIR probably brings back scarring memories of Java apps: slow, ugly, inconsistent, awkward.

I was also reminded of Evernote’s experience with .NET versus native code, which I blogged here.

Payne is not all wrong, neither is Jobs. That said, the distinction between what is good for users and what is good for developers is not absolute. Maintaining a single cross-platform code-base, for example, is good for both users and developers, because it reduces bugs and assists feature-compatibility across platforms. It is also good for users of minority platforms who might otherwise have nothing.

Another question: how many of the issues Payne identifies are inherent to using AIR (or another cross-platform runtime), and how many are implementation issues? It is impossible to know without drilling into the details; but I don’t believe that all AIR (or Java, or .NET) apps have “lousy performance”.

It is true that ActionScript code is slower than Java or .NET code, and much slower than compiled C/C++, but speed of script execution is not always the performance bottleneck that users will notice most.

This is seemingly one of those never-ending computing debates; but a post like Payne’s is a reminder that neither Adobe AIR, nor any cross-platform runtime, is a perfect solution to the challenge of multiple client platforms.

nginx market share growing faster than any other web server

According to the latest netcraft web survey nginx market share is growing faster than that of any other web server, even though it is still small relative to Apache or Microsoft IIS. In December 2010 nginx share grew by 0.88% to 7.5% – which can also be expressed as a 13.3% increase.

Apache 59.13%
Microsoft 21.00%
nginx 7.50%
Google 5.53%
lighttpd 0.68%

I did not take much notice of nginx until hearing Ryan Dahl evangelise it at Cloudstock, a Dreamforce event, last month. Now I plan to install it at itwriting.com when I find the time.

Microsoft WebMatrix released: a simple editor for ASP.NET Razor and more, but who is the target user?

Microsoft has released WebMatrix, a free tool for creating web sites for Microsoft’s web server. It uses the Web Platform Installer and installed smoothly on my Windows 7 64-bit box. What you get is a cleanly-designed tool which lets you start web sites from templates or from standard installs of popular applications including WordPress, Drupal and Moodle.

image

Yes, you can use PHP and MySQL as well as .NET web applications, though the common factor is that all are configured for IIS, Microsoft’s web server.

With many ISPs already offering instant installs of apps like WordPress, it is more interesting to look at the site templates in WebMatrix, though the selection is smaller.

image

What is interesting about these is that they create sites based on Razor, an alternative view engine for ASP.NET. Microsoft VP Scott Guthrie describes Razor here. It is odd though: Razor is a feature of ASP.NET MVC 3, currently in release candidate phase, but you cannot create ASP.NET MVC sites in Web Matrix.

Once a site is created, you can modify it in the WebMatrix editor.

image

You can run the site on IIS Express with one click. WebMatrix will show you all the requests as you run, which could be handy for tracing problems. There is also a database management workspace which uses SQL Server Compact Edition, a reporting workspace which will analyse your site for problems, and the ability to publish a site using  FTP or Microsoft’s Web Deploy.

I like the clean look of WebMatrix, and that it is lightweight and fast; but who is the target user? It appears to be aimed at non-professionals; but this is a techie product that will not appeal to users looking for an easy to use web site builder. There is no visual editor; users are just chucked in at the deep end editing raw HTML and C#. There is not even any intellisense code completion. Clicking Online Help just brings up a Microsoft search form. There is no debugger to speak of; you are expected to upgrade to Visual Studio. Which raises the question, why not just get Visual Web Developer 2010 Express, which is also free, and has a better editor and debugging features? Of course you could use the two together; but Web Matrix is not adding much value. Features like the SEO analysis seem to be be based on the existing Search Engine Optimization Toolkit, which you can install without Web Matrix.

WebMatrix has been available in beta for six months, but its forum is relatively quiet.

Still, if nothing else Web Matrix is a handy way to take a look at Razor, which deserves attention. Shay Friedman has a technical introduction here.

Guthrie has a detailed look at the WebMatrix beta here.

Half-baked Android tablets will help Apple, give hope to Microsoft

The downside of open is fragmentation. CES earlier this month was overflowing with Android tablets and smartphones, but since anyone can use Android, device manufacturers may disappoint users, for example by shipping tablets that do not use a version of Android designed for tablets, or shipping devices that do not have access to the official Android Market.

The Inquirer reported yesterday that the Asus tablets announced at CES will not in fact ship with Android 3.0 Honeycomb. The reason stated is that:

because the company did not know the detailed technical specifications requirements of the Android 3.0 Honeycomb operating system, it could not confirm that Honeycomb will be the tablets’ OS.

Although it is stated that the tablets will ship with Android 2.3 Gingerbread, I get the impression that Asus might upgrade them to Honeycomb eventually; and since they are now apparently not due until the third quarter there is time for plans to change.

Not all Android devices have Google’s official compatibility blessing.  The frequently asked questions make a good read:

Anyone is welcome to use the Android source code, but if the device isn’t compatible, it’s not considered part of the Android ecosystem.

Only devices that have passed Google’s compatibility tests get access to the Android Market. This leads to a surprising situation for users: you might buy an Android tablet or smartphone and find that it has no access to the Android Market.

Vendors can get round this to some extent by creating their own Android app stores, though this kind of fragmentation is likely to have a bad outcome, with a limited selection of apps and insufficient market share to attract developer attention.

This means that a handy question to ask a salesman is: does this gadget have the Android Market? If the answer is anything less than a demo of the official Google Android Market client, that is reason for caution.

The context is that all these devices have to compete with Apple; and the App Store is a significant part of the appeal of iOS devices. Therefore an Android device without access to the Android Market is disadvantaged, though it is not something you are likely to find mentioned on the box.

There is an obvious danger for Android, that customers confronted with a vast range of Android offerings will find it hard to distinguish between what is excellent, what is reasonable, and horrible implementations like the Next Tablet.

Even the element of uncertainty is enough to help Apple, which is likely to announce a second generation iPad soon. It may even give hope to Microsoft, depending on when “Windows 8” tablets come to market and how good they prove to be.

The challenge for Google is how to keep Android open, while also preventing its brand from being damaged by too many sub-standard devices.