The Cub's Lair

Be myself, be happy — An engibear's journey through Cloud Native, AI, and life.

As programmers, one of the most common things we do when debugging is logging—which basically boils down to continuously appending debug information to a text file.

Based on my day-to-day experience, I’ve noticed that we often need to measure the execution time of certain code blocks while logging. So today, I wrote a logging class that supports execution-time monitoring, and I’d like to share it with everyone. The download link is at the end of the post. Alright, let’s start with how to use it:

Read more »

In PHP, the explode() function splits a string into an array by a specified delimiter. Those who use this function regularly might have run into situations where the string contains the delimiter in parts you don’t actually want to split. For instance, splitting name|pass by | is completely fine, but if you have a string like myuser|pass|123, then pass and 123 will also be split apart. I encountered exactly this issue at work today, so I wrote a little helper function to handle it.

Read more »

To be honest, as a game developer, I absolutely despise game exploits and bots (外挂) because they ruin all the fun and cause games to die out prematurely. I really didn’t want to go down this road, but my slot machine account was completely broke, so I was forced to write a bot for it. Since yours truly (熊熊 - Beary) is the author of this slot machine app, I won’t be posting the complete code here (P.S. If everyone starts exploiting my slot machine, I’ll probably get assigned the task of adding anti-cheat mechanisms. Gotta save myself some extra work, hehe!). However, I will teach you guys how to write a bot for web games using PHP.

Read more »

What is Memcached?

Memcached (hereinafter referred to as MC) is a high-performance, distributed memory object caching system. By maintaining a unified, massive hash table in memory, it can store data in various formats, including images, videos, files, and database query results.

Why Use MC?

Data is a wonderful thing, but it struggles to respond quickly during high-frequency read/write operations. For large volumes of data that aren’t modified frequently, using MC is an excellent choice. You can think of MC as a giant dictionary: whatever data you need, you just provide a key and it instantly returns the value.

Where MC Is Not Suitable

Everything has two sides, and MC is no exception—it is by no means a magic bullet. Because it stores data using hashing, data retrieval can only be done through exact key matching. Therefore, never expect it to perform flexible queries like a relational database.

MC Protocol

https://lfbear.com/tool/mc.html

0%