Michaela Merz's personal blog site

It’s Old-School Baby ..

It’s Old-School Baby ..

Back in the days, coders didn’t have the convenience of stackoverflow or GitHub. You wanted to do something, you had to “invent” it yourself. We survived and thrived. Because we owned our source – and we understood it – every nook and cranny.

I ran into a problem the other day. A client had a LAMP environment and wanted to add a web-socket server that shared it’s data with the PHP server. Their coder tried a few things, like Apache and Node.js modules, but it didn’t quite work right. So they called and asked me.

Why don’t you do the server in PHP?

… I asked.

But .. the developer said .. PHP is single threaded and even with pthreads or forks, it’s not that simple to implement a full-fledged server. And I didn’t find anything helpful on Stackoverflow.

Oh my .. I thought. This guy takes home 6-figures but is utterly helpless when it comes to .. well .. thinking for himself. But I am a little unfair: I have plenty of experience in real problem solving under my belt. Sure I too use the usual web-sites. But not to quickly *solve* problems somehow, but to understand the different ways to a solution so that I am able to solve the problem myself.

Anyway – I told him about IRC – the Internet Relay Chat – which was a *big* thing 10 or 15 years ago. Some servers hosted thousands and thousands of users – without multi-threading. The technique used there could also be adapted into PHP: Non-blocking i/o

You have an array of network-socket handles and pass them to select() with an appropriate timeout. If any handle has something to read (or space to write), select will indicate that and you can read a number of bytes into a buffer linked to that handle and/or work with the data received. You may then return to the select() loop. If there’s nothing going on, select() times out and you can do something else. That’s pretty much all there is to it.

Coding that in PHP is easy. But it’s very old-school and that’s why not many people even bother with it. Many of today’s developers are more like folks buying a remote-controlled model-plane and throwing it into the air without even understanding the basic principles of aerodynamics. Maybe that’s why they invented drones?

There’s nothing wrong – in principle – to use third party elements in your own projects. After all – we use compilers, interpreters, servers and don’t think much about it. But when it comes to certain libraries, especially those that entice you to use some sort of cloud service, there are risks – and I am not (only) talking #infosec here. It leads your complete project, you customer, your company into a dependency that may not be advantageous. Sure – there are things that are unavoidable – if you want to use PayPal for example, but more often than not, developers are just to damn lazy to create their own stuff so they use libraries that move data around to a cloud-storage, sync-server or other off-premises processors. So unless you know what’s going on, you know what you want and what you are doing – you should seriously think about the implications of allowing any third party access to your environment.

Anyway – I helped the developer to build a flexible multi-user PHP web-socket server using non-blocking i/o and it turned out to work beautifully. No need to convert data, no need for a second environment that needs to be watched for security patches, it uses very little resources and serves the company and its 150 or so employees very well.

And the best of it all? He understands every little piece of it. It’s his code. Not a collection of BOOPS (Based On Other Peoples Stuff). And he became much more curious about understanding and solving problems – even if it means to temporarily abandon mainstream thinking. So – I guess I solved two problems at the same time.

Michaela Merz is an entrepreneur and first generation hacker. Her career started even before the Internet was available. She invented and developed a number of technologies now considered to be standard in modern web-environments. Among other things, she developed, founded, managed and sold Germany’s third largest Internet Online Service “germany.net” . She is very much active in the Internet business and  enjoys “hacking” modern technologies like block chain, IoT and mobile-, voice- and web-based services.

Leave a Reply

Your email address will not be published. Required fields are marked *