PHP shutdown handlers and exit codes

I was in bed trying to get to sleep but my brain wanted to know the answer to this question. So I was forced out of bed to write this experiment:

function main( $argv ) {

  register_shutdown_function( 'shutdown_1' );
  register_shutdown_function( 'shutdown_2' );

  exit( 0 );

}

function shutdown_1() {

  exit( 1 );

}

function shutdown_2() {

  exit( 2 );

}

main( $argv );

With this PHP code, what do you expect is the resultant error level?

The answer is ‘1’. After main() calls exit( 0 ) the shutdown function shutdown_1() is invoked. When shutdown_1() calls exit( 1 ) the process exists and shutdown_2() is never called.

I’m glad we cleared that up. Back to bed.

Context object versus global variables

I’m reading A Philosophy of Software Design by John Ousterhout and he says:

The context object unifies the handling of all system-global information and eliminates the need for pass-through variables. If a new variable needs to be added, it can be added to the context object; no existing code is affected except for the constructor and destructor for the context. The context makes it easy to identify and manage the global state of the system, since it is all stored in one place. The context is also convenient for testing: test code can change the global configuration of the application by modifying fields in the context. It would be much more difficult to implement such changes if the system used pass-through variables.

Contexts are far from an ideal solution. The variables stored in a context have most of the disadvantages of global variables; for example, it may not be obvious why a particular variable is present, or where it is used. Without discipline, a context can turn into a huge grab-bag of data that creates nonobvious dependencies throughout the system. Contexts may also create thread-safety issues; the best way to avoid problems is for variables in a context to be immutable. Unfortunately, I haven’t found a better solution than contexts.

Okay, so I’m just gonna step way out of line over here and suggest something heretical… but shouldn’t you just use global variables? You only introduced the context object so you could tweak it in unit tests, and you could just change your tests so that each one ran in a new process. Just sayin’.

…I suppose for the sake of completeness I should add a little more from Ousterhout which he said prior to the above:

Another approach is to store the information in a global variable, as in Figure 7.2(c). This avoids the need to pass the information from method to method, but global variables almost always create other problems. For example, global variables make it impossible to create two independent instances of the same system in the same process, since accesses to the global variables will conflict. It may seem unlikely that you would need multiple instances in production, but they are often useful in testing.

…so he is bending over backward to support multiple tests in one process, but he could just run each test in its own process and his problem evaporates.

Oh cringe

Man. So. Today, this happened. I was watching a new video from Adrian Black and his EEVBlog multimeter failed:

It's disappointing that it's already failed

I have been saving my pennies and planning to buy an EEVBlog 121GW Multimeter because a lot of the makers around the interwebs have one as a nod to Dave Jones over on the EEVBlog, but that’s just so embarrassing that it’s failing. Of all the equipment you have you need to trust your test equipment the most and this is… well, just sad I guess.

Logic Analyzer with 1GHz Sampling Rate

Today I was pleased to discover this: DreamSourceLab DSLogic U3Pro32 USB-Based Logic Analyzer with 1GHz Sampling Rate, 2Gbits Memory, USB 3.0 Interface, 32 Channels.

There are some notes from the manufacturer over here: DSLogic Series USB-based Logic Analyzer.

It’s a logic analyzer which can operate at 1GHz that’s within my price range. I’m not rushing off to buy this thing, but it is certainly on my list.

The only other thing I have seen that compares to this logic analyzer is this RIGOL DS70304/DS70504– Digital Oscilloscope 3GHz/5GHz 4 Channel 20GSa/s 2Gpts 1000000 wfms/s which is roughly two orders of magnitude more expensive.

Diode Experiment | Project 3/10 | Maxitronix 10in1 | Learning Electronics In The Lab With Jay Jay

This post is part of my video blog and you can find more information about this video on this show’s homepage which is here.

You can support this channel on Patreon: patreon.com/JohnElliotV

In this video I do the third Maxitronix 10in1 Electronic Project Lab project: Diode Experiment.

When I looked at the resistor on the bottom I thought it was red – brown – black – gold which would have been 21Ω but I think I misread brown and that was actually purple which would be 27Ω which stacks better with the two measurements I made both of which said 27Ω.

In the video we examine the forward voltage of our germanium diode and get various readings. Typically a germanium diode should be around 0.3V versus silicon diodes which are usually around 0.7V.

The component testers we use are these:

On the FNIRSI component tester the Ir is the “reverse current”, also known as the “leakage current”. This is the small amount of current which flows through the diode when it is reverse biased (that is, basically, connected the wrong way around).

I asked ChatGPT a few questions about diodes and their specifications which you can read here: Germanium Diode Forward Voltage if you’re at all interested in such things. Of course you should be doubly suspicious of anything you read on the internet. :)

The really amazing learning for me in this experiment was how hot the germanium diode got versus the lamp, which was so surprising. Just goes to show how good an idea it is to actually do experiments and measure things! The thermal imager we used was the UNI-T UTi260B.

Also I think I’m coming around to the view that an oscilloscope is a pretty poor voltmeter. My oscilloscope is an MSO5074 70MHz 4 Channel MIXED SIGNAL OSCILLOSCOPE and I love it but I think in future I will limit my use of the oscilloscope to situations where I’m actually dealing with some sort of oscillator. I think simple digital multimeters would have been better test equipment to use for the kinds of readings I was trying to take in this experiment.

I hope you enjoy the video. Stay tuned for the upcoming projects. If you’re interested in seeing them don’t forget to subscribe!

Also, if you’re interested in getting any of these Maxitronix kits yourself the best place I know to look is on eBay. Let me know if you find them somewhere else!

Thanks very much for watching! And please remember to hit like and subscribe!


Following is a product I use picked at random from my collection which may appear in my videos. Clicking through on this to find and click on the green affiliate links before purchasing from eBay or AliExpress is a great way to support the channel at no cost to you. Thanks!

aToolTour Black Hexagon Deburring Drill BitThis is an image of the product.notes

Let’s go shopping!

Propagation of electricity

Thanks to Craig for referring me to Brian Haidet’s AlphaPhoenix channel.

I found the following four videos on the AlphaPhoenix channel explaining various aspects of the propagation of electricity, which goes some way to explaining how the high impedance headphone might work in my 10in1 2/10 project.

While watching the videos I discovered that Brian’s oscilloscope is a Siglent SDS1104X-E (100 MHz) Oscilloscope, a pretty nice looking bit of kit!

Hardware debugging

Read a bunch of stuff about hardware debugging. Learned a thing or two, but I have much further to go!