Okay, so back to the whole studying thing. The section I left off at yesterday was Bitwise operations. These kinds of operations require me to sit down with a piece of paper and make some doodles (which was not available yesterday).
Okay, so back to the whole studying thing. The section I left off at yesterday was Bitwise operations. These kinds of operations require me to sit down with a piece of paper and make some doodles (which was not available yesterday).
At work, I occasionally need to move database changes from the development server to the live server. We have about a hundred tables, which makes it difficult to review by hand. So there is a comparison script that basically runs a `mysqladmin` schema dump on both databases and then diffs the two files. The result is a little difficult to decipher at times and still requires manual scripting to make the final ALTER commands.
What if I could run a PHP script that would compare any two schemas and generate proper ALTER commands to correct the two of them. I would probably use some combination of these SQL commands:
I’m going to have to think about this tonight. Maybe punch out a test script tomorrow.
Before I start with my progress, I’d love to share an awesome command I wrote the other day. I’m writing some intensive PHP scripts for my job that need to be run in the background and on multiple threads to increase speed and to provide the user with an asynchronous experience. I was going to use PCNTL, but it wasn’t compiled into the system I was on, so I ended up spawning off tasks as separate background scripts. The problem I ran into was that the website would grind to a halt because the scripts (usually 5 active at a time) would run on all four cores and take up 100% of the CPU. So what do I do? I need to run these scripts, but I need the website to continue to be operational.
My first choice was to play with the nice level of the process “proc_nice()” That worked at first, until I started dealing with 20-30 scripts at once. Then the *nix box decided to just throw EVERYTHING to the lowest priority just to keep the server up. Then I realized, I have four cores, why take up every core? After some research, I came across the “taskset” command which allowed me to specify which core my process will run on. Take a look at the following code:
exec("taskset -c ".($i % 2)"; php theScript.php > /dev/null 2>&1 & echo $!", $opt);
Assuming we’re in a loop with $i as the index, this will spawn the intensive processes into the background and balanced on the first two cores only. Also, if you read in “$opt[0]” you can return the pid of your new running process (if you needed to kill it later). Anyway, I was really proud of this line of code and thought I’d share it. Back to the studying.
The first chapter is all about PHP Basics. And as a PHP programmer for ~6 years, it shouldn’t be anything new. Here are some interesting things I didn’t know:
Okay, so it’s been a long time since I posted anything. Let’s just say I’ve been busy. I got a new job (Senior Web[PHP] Developer), been teaching every week (Graduate Computer Science Web Development class), and have been playing a lot of video games (Assassin’s Creed 2, Call of Duty: Modern Warfare 2, and Fallout 3). Anyway, it occurred to me last week that I failed to achieve my goal of getting Zend PHP certified before September and I’m about to teach the first Graduate level PHP/MySQL class at Sacred Heart University in April 2010.
I can’t really go into this class without having something to prove to the students that I know what I’m talking about. It’s hard when the teacher (me) is half the age of most of the students. How can they respect me without something to show them that I earned my place at the whiteboard. I have my degrees, I have my job, and I have the dozens of websites I’ve developed. But somehow I’m afraid that is not enough.