PHP: Process Control Functions

I had quite forgotten that PHP can fork a process just like in C! This might be a useful thing to know for doing background tasks, but to be honest the extra complexity required will probably put me off doing it. That’s where this Thread class comes in handy..

<?php
include ("threadClass.php");

class testThread extends Thread {

  function testThread($name) {
    $this->Thread($name); // calls the parent constructor and assign its name
  }

  function run() {
    while(true) {
      sleep(1);
      print time() ."-" . $this->getName() . " said ok...\n"; // every second we're going to print this line...
    }
  }
}
// Main program. Bring up two instances of the same class (testThread).
// They runs concurrently. It's a multi-thread app with a few lines of code!!!

$test1 = new testThread ("Thread-1");
$test2 = new testThread ("Thread-2");
$test1->start();
$test2->start();

print "This is the main process. Press [CTRL-CANC] to terminate.\n";
while(true) {sleep(1);}

?>

Busy

You can tell I’m busy. No posts today so far. Installing Apache, MySQL, PHP on a new machine, and fiddling with firewalls.
Anyone good at iptables stuff? How do I let MSN Messenger through? The following would work fine if not for Messenger!

# /etc/sysconfig/iptables
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Lokkit-0-50-INPUT - [0:0]
-A INPUT -j RH-Lokkit-0-50-INPUT
-A FORWARD -j RH-Lokkit-0-50-INPUT

# lan
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp -s 192.168.1.0/255.255.255.0 -d 0/0 -j ACCEPT

# ssh
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --dport 22 --syn -j ACCEPT

# smtp
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --dport 25 --syn -j ACCEPT

# dns
-A RH-Lokkit-0-50-INPUT -p udp -m udp -s dns1_server1 --sport 53 -d 0/0 -j ACCEPT
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp -s dns_server2 --sport 53 -d 0/0 -j ACCEPT

# localhost
-A RH-Lokkit-0-50-INPUT -i lo -j ACCEPT

# reject everything else
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --syn -j REJECT
-A RH-Lokkit-0-50-INPUT -p udp -m udp -j REJECT
COMMIT

I found reAim which is a compact transparent proxy designed to be run on or behind a Linux IPTables based firewall.
Trying to proxy through Squid didn’t work either, I got the following error:

TCP_DENIED/403 1020 CONNECT messenger.hotmail.com:1863 – NONE/- –

That’s annoying.

b2++ forum and documentation

I added a discussion forum and documentation site for b2++. Both are quite empty right now, but you can post to the forum if you have any queries or comments about b2++, and if you’d like to contribute to the documentation feel free to email me and I’ll setup an account for you to edit pages in the Wiki.
The documentation is handled by WakkaWiki but I’ve limited editing by requiring a username/password.
The forum is running a stock version of phpBB.

The b2 future – WordPress

Michel’s back, and announced details about the future of b2.
WordPress is going to be the next version of b2 and is developed by Mike Little and Matt Mullenweg. I’ve exchanged brief emails with both on different matters and hope to continue exchanging ideas and code as we’re working on a similar codebase. Tim has more on the announcement too.
With b2++ and WordPress around, the future of b2 looks good! 🙂
On another note, there’s a security hole in the blog import tools shipped with b2. I bundled these scripts with b2++. The easiest way of fixing that is by deleting gm-2-b2.php and blogger-2-b2.php.