Skip to content

Category: Erklärbär

WordPressing…

This blog is running a WordPress, using Ubuntu, Apache and MySQL. So it’s a very basic installation.

I made all this with a tiny Scaleway VM and Ansible. My Goal has been to install this thing without actually having to log into the VM (“Look Mom, no hands!”). Of course, I have been logging into the VM, but that’s mostly for checking things are going well.

8 Comments

Containers 101

It is helpful to remember that containers are just normal Unix processes with two special tricks.

Normal Unix Processes

Unix starts processes by performing a fork() system call to create a new child process. The child process still contains the same program as the parent process, so the parent processes program still has control over the child. It usually performs a number of operations within the context of the new child, preparing the environment for the new program, from within.

PID 17 forks, and creates a new process with PID 18. This process executes a copy of the original program.

Then, after the environment is complete, the parent program within the child processes context replaces itself by calling execve(). This system call unloads the current program in a process and reuses the process to load a new program into it.

Leave a Comment

Load, Load Testing and Benchmarking

(In order to be able to give up the test blog at blogspot.nl, I am moving content over)

So you have a new system and want to know what the load limits are. For that you want to run a benchmark.

Basic Benchmarking

The main plan looks like this:

The basic idea: Find a box, offer load, see what happens, learn.

You grab a box and find a method to generate load. Eventually the box will be fully loaded and you will notice this somehow.

Leave a Comment

git Improvements for Monorepos

Microsoft has been doing things to git, they report.

[W]e […] have a handful of teams with repos of unusual size! For example, the Windows codebase has over 3.5 million files and is over 270 GB in size. The Git client was never designed to work with repos with that many files or that much content. You can see that in action when you run “git checkout” and it takes up to 3 hours, or even a simple “git status” takes almost 10 minutes to run. That’s assuming you can get past the “git clone”, which takes 12+ hours.

What Microsoft is doing here is called a Monorepo approach. It not insane, has many advantages and is being discussed at length at Dan Luu, and is also in use with Facebook and Google and in many other places. But git is running into problems handling very large Monoreports, as discussed in an article at Atlassian.

What Microsoft GVFS does, according to their paper, is addressing the issues git has instead of working around them. And that is an awesome thing.

Leave a Comment

Command line access to the Mac keychain

I am getting my payslips in electronic form, as an encrypted, password protected PDF. It’s not a super secret password, and the encryption is more against accidentally opening the file than it is to keep the content of the file actually secret.

After shipping the PDF home, I am archiving it for tax purposes, but in order to make the archival safe, I am storing the original file as well as the decrypted cleartext version of it. To do that, I wrote a shell script, which contained the password in a variable in clear.

Discussing that at work had a few people rejecting the storage of keys in a script in clear as a matter of principle, and the suggestion was to use the operating system key management service to hold this kind of data.

Here is how to interact with the key management of MacOS.

Leave a Comment

PHP 7: mysql extension deprecated

In mysql() nach PHP 7 retten, Charly Kühnast explains how you can get the deprecated and disabled mysql extension back in PHP 7. You shouldn’t.

There are many reasons for this. One of them being that none of the newer features in MySQL can be used with the old mysql extensions. There is an overview in the PHP documentation that explains exactly what you are missing.

One of the things that you are missing is support for prepared statements. Prepared statements are a mechanism in which you write SQL statements with placeholders for variables, and then later bind values to the placeholders using a “bind” call or as part of the “execute” call which is actually running the statement. In any case, the variables are being escaped properly automatically, making SQL injection a lot harder.

This is not just a problem limited to PHP – a search for bind and execute other sources can be very instructive. For example, the sources of Opennebula or in older versions of Owncloud (up to and including version 7) are rich treasure troves of potential exploits.

So currently the situation is as follows:

There are three extensions at the PHP level, one of which is deprecated and disabled in PHP 7:

  • The old mysql extension is no longer available by default, and for good reasons. Do not use it, do not attempt to use code that uses it.
  • The mysqli extension has been around for very many years, and offers a procedural and an object oriented interface, and makes “newer” MySQL features available, including prepared statements.
  • The PDO_mysql extension has been around for many years, too, and offers an object oriented, and portable across databases interface. It also allows access to all “newer” MySQL features.

The wire protocol of all of these extensions is implemented by a C-level library, against which the extension can be linked. A manual page explains the choices.

  • Traditionally that has been the Oracle/MySQL C-API (“libmysqlclient”, “Connector/C”), which comes with the database server. It is available on the GPL, which is a license different from the PHP license of the rest of the PHP proper, and it has it’s own memory management, which is different from the PHP native memory management.
  • Since PHP 5.3, there is mysqlnd (the “native driver”, ND). It re-implements the MySQL wire protocol, and is available under the same license as PHP itself. It also uses the same memory management that PHP uses, which makes it faster (no copying) and more efficient (no duplication of values). It is the default on a normal PHP build these days.

What you should be using: These days, your code should not be using the mysql extension. So you will be using mysqli or PDO_mysql, depending on your needs, with the underlying implementation of the native driver doing the heavy lifting.

Do not attempt to port mysql-Extension based code to PHP 7 without refactoring it for prepared statements, please.

 

Leave a Comment