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:
-
<p>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.</p>
-
<hr />
-
<p>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:</p>
-
<p><span id="more-396"></span></p>
-
<ul>
-
<li>You can use <strong>asp tags</strong> <% %> instead of<strong> standard tags</strong>
-
<php ?> via a configuration option. “Nobody quite understands why ASP tags were introduced” – Study Guide </li>
-
<li>The first newline after the closing tag ?> is <strong>ignored by the parser</strong> to prevent any extra data being sent to the browser.  Imagine you were outputting a binary file and you sent an extra /n/r.  That could cause a lot of trouble. </li>
-
<li>In the same context, <strong>omitting the closing tag</strong> ?> is perfectly legal. </li>
-
<li><strong>Comments</strong> are done by //, # (did not know that) and /*  */ (multiline).  However, if you put a closing tag ?> in a comment:
-
<pre lang="php">// This is a comment
-
// This is a closing tag ?> did you know that?
Then the browser would actually output " did you know that?" because it would stop parsing PHP after the ?> Even inside a comment block. Hmm...
- Scalar:
- boolean (true or false): number to boolean = false if == 0, true otherwise. string to boolean = false if == ”0” or “”, true otherwise.
- int (signed integer): standard decimal, octal signified by leading zero (0755), and hexadecimal signified by leading 0x or 0X.
- float (signed floating-point): standard decimal and exponential signified by e or E (2e10).
- string (collection of binary data).
- Compound:
- Arrays: containers of ordered data elements.
- Objects: containers of both data and code.
-
$$test = "moon";
-
echo $cheese; // outputs "moon"
This is just plain crazy as you can, theoretically, create any variable name you want. Even a variable called $123456. You would have to access it using curly braces ${123456}, but you could still use it.
I’m going to end just before Bitwise Operators, as I’m going to need to sit down with a clean piece of paper before I attempt to tackle them. Until tomorrow.

