Key Takeaways

  • Appserver.io is a PHP application server system that has moved from alpha to a production system, currently in version 1.0.6. It addresses the need for high performance in large applications from a server resource optimization and collaboration perspective, a demand frequently voiced by professional PHP developers.
  • Appserver.io utilizes threading technology, which is rare in the PHP world. This feature allows modern computers to multitask, and is implemented in appserver.io to support the development of threaded applications.
  • Appserver.io also allows for better collaboration between web servers in a web application environment, but this requires a shift in perspective from PHP developers. The server provides the potential for more performance, but it cannot achieve this alone.
  • Appserver.io offers a Community Edition licensed under the Open Source License 3.0, as well as a Professional Edition and an Enterprise Edition. The installation process is simple across various operating systems, and once installed, the routine automatically starts the appserver process.

It has been just over a year and a half since the team at TechDivisionGmbH were interviewed here on Sitepoint about their paradigm changing PHP application server system called appserver.io. At the time of the interview, appserver was just breaking out as an alpha. Since then, a lot has happened and appserver is now GA as a production system, currently in version 1.0.6, with version 1.1.0 on the horizon.

You’re probably asking, “Why is appserver paradigm changing?”

The answer is, because it tackles the last frontier of PHP application development: high performance for large applications from a server resource optimization and collaboration perspective. This is the realm of PHP development which a good number of professional PHP developers have been calling for, like Manuel Lemos in his “PHP7 Features and Release Date” blog (see the section about a “Standalone Multi-threading Web Server”) and Fabien Potencier, father of Symfony, in his presentation “My Take on PHP”, where he notes he is also working on such an application server solution himself. Well, look no longer Fabien, we already have a really good solution with appsever.io.

Appserver Community Edition is licensed under the Open Source License 3.0. The TechDivsion team also offer a Professional Edition and an Enterprise Edition too.

Appserver Still Needs the Developer

Although the potential is within appserver to offer more performance and better collaboration between webservers in a web application environment, it cannot do it alone. It also requires new thinking from the PHP developer. It is this different perspective on solving problems, which we will dive into, with this 3 part series.

In this first part, we will go through very high level concepts that make appserver special and get you started with your first installation. In Part 2, we will go over the components appserver offers out-of-the-box in detail. And finally, in part 3, we will run with some use cases given to us through the example app provided in the installation package.

The overall goal of this series will be to get your perspective opened to the new world of a possibly more performant application system with PHP and appserver and how it requires changes in development thinking and in some cases workflow.

Threads and Threading

You might understand threading as the technology which allows modern computers to do multiple things at once. This is correct and where the term “multi-tasking” actually comes from.

Threading or multitasking in the PHP world is actually quite rare. In the days when PHP was created, threading in computers wasn’t really much of a concern. PHP has stayed in line with its single-threaded architecture, also called “shared nothing” architecture, even to this day.

What most people don’t realize, however, is that PHP is actually built to also support multitasking. This gem of functionality was basically unknown until Joe Watkins created pthreads, a powerful PHP extension which allows a developer to build threaded applications in PHP. It is this functionality, among other important features, which appserver implements to support the development of threaded applications.

Still, you might be like me and wondering why this threading stuff makes any kind of difference for a PHP application. For that, we must actually take a look at a bird’s eye view of today’s webserver technology.

The Standard PHP Web Server Scenario

For us PHP developers, in the context of webservers, the thought of threading is far from our minds. That’s because the webservers and/or PHP process managers themselves are actually doing that work. You might be saying, “Great! That is one less problem for me to worry about” and you’d be absolutely correct in saying that. However, this handling of threading at the webserver / PHP process management level comes with a pretty big cost. Below is an animation of the current way PHP runs its processes with a webserver like Nginx.

The threading is done by duplicating, building, and destroying the same things over and over again, for each request the server receives. You might be thinking, this doesn’t look so bad, right? To see the real cost, we actually have to dive in a bit deeper and get into the “build/destroy” part of the process.

This image shows what a normal, usually larger application supported by some MVC framework must do for every single call made to it. We can argue about the sequence of events. However, what is important to notice is, there is a lot of work being done only to be completely destroyed after the response is sent. As mentioned above, this is a lot of duplicated and wasted effort for the machine. This waste = lost performance!

Now let’s look at an appserver scenario from that bird’s eye view.

The Appserver Scenario

As you can see, nothing all too different. However, with appserver, the webserver is written in PHP and is an integrated part of the app. Now you have one less worry and, if necessary, you have more control over what is happening within the webserver. Also due to the webserver being integrated, a common part of modern PHP frameworks that deals with the HTTP requests and responses is basically put into its proper place in the stack, within the webserver itself.

This alone would be a great improvement over the standard webserver, however, it gets even better. Let’s look at the next level down, as we did earlier.

Notice how certain parts of the programming are no longer destroyed. What is destroyed or not is now in the developer’s hands. It means the developer can, for instance, allow the bootstrapping process to stay “threaded” and never have to be rebuilt for each request. The bootstrapped app is always ready to go.

A Difference in Thinking

When the difference appserver makes went “click” in my mind, this is about how I felt (click to view).

ScreenShot

Having fun? Oh yes! And the most important part of the movie is what God says after this scene.

Parting your soup is not a miracle, Bruce. It’s a magic trick. A single mom who’s working two jobs and still finds time to take her kid to soccer practice, that’s a miracle. A teenager who says “no” to drugs and “yes” to an education, that’s a miracle. People want me to do everything for them. But what they don’t realize is they have the power. You want to see a miracle, son? Be the miracle.

Ok, maybe that is a bit melodramatic, but for sure, the “miracle” or the ability to make parts of your program basically persist within the server itself is a powerful tool to add performance to your applications. It allows you, as the PHP developer, to think differently about how an application can work better and faster. Though, as the rule goes…

With great power comes great responsibility.

In other words, although you may have new powers at hand with appserver, you must also understand the meaning of those powers, how to use it and also the possible bad side-effects that can happen, when you aren’t careful. We’ll get into these things in more detail in the later parts of the series.

For now, let’s get you up and running with an appserver instance.

Installation and Getting Started

Appserver comes ready to install for a good number of operating systems. A recommended approach to local development is to use a Vagrant VM built with Virtualbox. Or you could run with Bruno’s quick tip to build his homestead box. We will be installing the Debian Wheezy version of appserver and you will actually only need the running OS.

After you have installed the VM and it is running, SSH into it and carry out these commands as the super-user.

echo "deb http://deb.appserver.io/ wheezy main" > /etc/apt/sources.list.d/appserver.list
wget http://deb.appserver.io/appserver.gpg -O - | apt-key add -
apt-get update
apt-get install appserver-dist

The installation process is just as simple with the other OSes too.

No matter which method you used to install appserver, you should be up and running with appserver. The installation routine automatically starts the appserver process after installation is complete. To check this quickly, enter the following.

service appserver status

You should see a running appserver.

[ ok ] appserver is running.

A small note: If you reboot your VM, appserver will not run automatically. If you’d like to have it running at reboot, you need to set up the service to start at boot time. With Debian, you can carry out this command.

update-rc.d appserver defaults

If you want appserver to actually serve up your web applications in general, you can also change appserver’s listening port to 80. To do this, you now need to make a simple change to the core configuration file in appserver. Go to /opt/appserver/etc/appserver and you will find a file called appserver.xml. This is the core configuration file for the webserver, much like Apache’s httpd.conf or Nginx’s nginx.conf files. Open it up in your favorite editor and find these lines.

<server
            name="http"
            ....
            <param name="admin" type="string">info@appserver.io</param>
            <param name="transport" type="string">tcp</param>
            <param name="address" type="string">0.0.0.0</param>
            <param name="port" type="integer">9080</param>
If you are just experimenting, it would be best to leave the port as is. This way, you can play with appserver next to any other PHP projects.

There is a lot more you can do with the webserver and this configuration file. We’ll be going over some of the possibilities in the later posts.

If you did make any changes to the configuration file, you’ll need to restart appserver in order for the changes to take effect.

service appserver restart

If all went well, you should be able to enter your VM’s IP address with :9080/example, like http://10.10.10.10:9080/example, and you should see the starting page of the example app already installed in appserver.

That’s it! You now have a running appserver. In the next part of the series, we will dig into the features of appserver and see what it offers out of the box. Stay tuned for more!

Frequently Asked Questions (FAQs) about PHP-Based Servers

What are the key features of Appserver, a PHP-based server?

Appserver is a unique PHP-based server that offers a multitude of features. It provides a multi-threaded environment, which allows for concurrent processing of requests. This is a significant advantage over traditional PHP servers, which are single-threaded. Appserver also supports HTTP/2, which can significantly improve the performance of your web applications. It also provides a persistent object store, which can help to reduce the overhead of object creation and destruction. Moreover, Appserver supports the Servlet API, which can make it easier to build complex web applications.

How does Appserver compare to other PHP servers?

Appserver offers several advantages over traditional PHP servers. It provides a multi-threaded environment, which can significantly improve the performance of your web applications. It also supports HTTP/2 and the Servlet API, which are not commonly found in other PHP servers. However, it’s important to note that Appserver may require more resources than other PHP servers, due to its multi-threaded nature and the additional features it provides.

How can I set up Appserver for production use?

Setting up Appserver for production use involves several steps. First, you need to install Appserver on your server. This can be done by downloading the Appserver installer from the official website and running it. Once Appserver is installed, you need to configure it for your specific needs. This involves setting up the server environment, configuring the server settings, and setting up your web applications. Finally, you need to start Appserver and ensure that it is running correctly.

What is the Servlet API and how does it work with Appserver?

The Servlet API is a standard for building server-side web applications. It provides a set of interfaces and classes that can be used to handle HTTP requests and responses. Appserver supports the Servlet API, which means that you can use it to build complex web applications. When a request is received by Appserver, it is passed to the appropriate servlet for processing. The servlet then generates a response, which is sent back to the client.

What is HTTP/2 and how does Appserver support it?

HTTP/2 is a major revision of the HTTP protocol, which is used for transferring data on the web. It offers several improvements over the previous version, including multiplexing, header compression, and server push. Appserver supports HTTP/2, which means that it can take advantage of these features to improve the performance of your web applications.

What is a persistent object store and how does Appserver use it?

A persistent object store is a storage system that allows objects to be stored and retrieved across different sessions. This can help to reduce the overhead of object creation and destruction, which can improve the performance of your web applications. Appserver provides a persistent object store, which can be used to store and retrieve objects.

How does Appserver handle concurrent requests?

Appserver handles concurrent requests by using a multi-threaded environment. When a request is received, it is assigned to a separate thread for processing. This allows multiple requests to be processed at the same time, which can significantly improve the performance of your web applications.

How can I configure Appserver for my specific needs?

Configuring Appserver for your specific needs involves setting up the server environment, configuring the server settings, and setting up your web applications. This can be done through the Appserver configuration file, which allows you to specify various settings such as the server port, the number of threads, and the location of your web applications.

What resources does Appserver require?

Appserver may require more resources than other PHP servers, due to its multi-threaded nature and the additional features it provides. This includes CPU, memory, and disk space. However, the exact requirements will depend on your specific use case.

Where can I download Appserver?

You can download Appserver from the official website. The installer is available for various platforms, including Windows, macOS, and Linux. Once downloaded, you can run the installer to install Appserver on your server.

Scott MolinariScott Molinari
View Author

Scott has been supporting customers using powerful PHP applications like Wordpress, vBulletin and Xenforo in his spare time for over 13 years. His company (also ran as a hobby) was the distributor for the German version of vBulletin for 12 of those years. The past year and a half, he's been taking on more of the developer roll and is now learning about new technologies for his new project Skooppa.com. His goal at Sitepoint is to share these new technologies with the PHP community.

appserverBrunoSOOPHPPHPserverthreads
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week