Learned about spl_object_hash via Stack Overflow. Provides a unique object id in PHP.
Author Archives: Jay Jay
PHP Traits and Grafts
Reading about traits and grafts in PHP: Request for Comments: Horizontal Reuse for PHP, PHP Traits, Using Traits in PHP 5.4 and PHP Traits: Good or Bad?. They mentioned the Diamond Problem.
I learned some new syntax too! E.g.:
return $_instance ?: $_instance = new $class;
The ternary operator as a ‘binary’ operator! Cool! See here for details: Since PHP 5.3, it is possible to leave out the middle part of the ternary operator.
Observe, and act with clarity
The trance mix I’m listening to at the moment is repeating: “Observe, and act with clarity.” — Great lyrics! The track is reported as “Dimension 5 – Radio Mix” on the goapsy channel on di.fm.
PHP range — Create an array containing a range of elements
Today I discovered the PHP range function…
Running Apache as ME!
On my development machine I want Apache to run under my user id so I can automatically generate files (and have permission to write them).
I configured Apache like this:
root@mercy:/etc/apache2# grep -R www-data . ./envvars:export APACHE_RUN_USER=www-data ./envvars:export APACHE_RUN_GROUP=www-data root@mercy:/etc/apache2# vim envvars export APACHE_RUN_USER=jj5 export APACHE_RUN_GROUP=jj5 root@mercy:/etc/apache2# apache2ctl graceful /var/lock/apache2 already exists but is not a directory owned by jj5. Please fix manually. Aborting. root@mercy:/etc/apache2# chown jj5:jj5 /var/lock/apache2 root@mercy:/etc/apache2# apache2ctl graceful
Easy-peasy!
Wait… that didn’t work. The problem was apache2ctl graceful didn’t pick up the new envvars file, this fixed it:
root@mercy:/etc/apache2# /etc/init.d/apache2 restart
Setting the MySQL timezone per connection
Reading about Setting the MySQL timezone per connection which I had to do like this:
db()->exec( "set time_zone = '+0:00'" );
MySQL Connection Character Sets and Collations
Reading about MySQL Connection Character Sets and Collations…
Linux RAM Disk
Reading about how to create a RAM disk on Linux:
# mount -o size=200M -t tmpfs none /mnt/tmpfs
PHP PDO MySQL Blob
Read PHP MySQL BLOB today to learn how to work with BLOBs. Basically:
public function insertBlob($filePath,$mime){
$blob = fopen($filePath,'rb');
$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':mime',$mime);
$stmt->bindParam(':data',$blob,PDO::PARAM_LOB);
return $stmt->execute();
}
function updateBlob($id,$filePath,$mime) {
$blob = fopen($filePath,'rb');
$sql = "UPDATE files
SET mime = :mime,
data = :data
WHERE id = :id";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':mime',$mime);
$stmt->bindParam(':data',$blob,PDO::PARAM_LOB);
$stmt->bindParam(':id',$id);
return $stmt->execute();
}
public function selectBlob($id) {
$sql = "SELECT mime,
data
FROM files
WHERE id = :id";
$stmt = $this->conn->prepare($sql);
$stmt->execute(array(":id" => $id));
$stmt->bindColumn(1, $mime);
$stmt->bindColumn(2, $data, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
return array("mime" => $mime,
"data" => $data);
}
info: mpt raid status change
Getting spammed courtesy my Debian VMWare image, notifying me of an “mpt raid status change”. Looked here and fixed the problem with:
# /etc/init.d/mpt-statusd stop # update-rc.d -f mpt-statusd remove