Everybody Staze...

Nobody leavz...

  • Home
  • About Me
    • LinkedIn
    • Lab
  • Contact
  • Links
  • Reviews
  • Sitemap
  • Weather
You are here: Home / Archives for PHP

Decoding Apple Serial Numbers for Date of Manufacture

2016/03/30 By staze

At work, I’ve been heading up an Asset Management project. Inventorying everything we have, adding it to a system, and then figuring out replacement cycles, amortization, etc. Part of this has been figuring out purchase dates for things like Macs, without asking our overloaded accounting office for invoices for a couple hundred machines.

Some investigation led me to two websites, one covering the new serial numbers, and the other covering older serial numbers. Basically, they used to be very readable with numbers representing their actual numbers. Then Apple switched to using Base-27 to represent year (first or second half), and then week was similar (using a limited set of letters and numbers).

Using that information, I’ve created the following script (yes, it’s pretty ugly PHP) that should decode both old 11 digit serials, and new 12 digit ones. Because of my use case, it adds some time to the manufacturing date to come up with a reasonable “purchase date” that I then use ((in my case, it just figures the purchase date was the start of the term following manufacture)). Feel free to use, modify, etc. I just built this because the sites that actually give manufacture date usually have limits on the number of queries per hour/day etc.

Thanks!


‘2005-1’,
‘1’ => ‘2005-2’,
‘2’ => ‘2006-1’,
‘3’ => ‘2006-2’,
‘4’ => ‘2007-1’,
‘5’ => ‘2007-2’,
‘7’ => ‘2008-2’,
‘8’ => ‘2009-1’,
‘9’ => ‘2009-2’,
‘C’ => ‘2010-1’,
‘D’ => ‘2010-2’,
‘F’ => ‘2011-1’,
‘G’ => ‘2011-2’,
‘H’ => ‘2012-1’,
‘J’ => ‘2012-2’,
‘K’ => ‘2013-1’,
‘L’ => ‘2013-2’,
‘M’ => ‘2014-1’,
‘N’ => ‘2014-2’,
‘P’ => ‘2015-1’,
‘Q’ => ‘2015-2’,
‘R’ => ‘2016-1’,
‘S’ => ‘2016-2’,
‘T’ => ‘2017-1’,
‘V’ => ‘2017-2’,
‘W’ => ‘2018-1’,
‘X’ => ‘2018-2’,
‘Y’ => ‘2019-1’,
‘Z’ => ‘2019-2’
);

//Years for 11 digit serial. Yes, it ignores the year 2000 and before.

$years11 = array(
‘0’ => ‘2010’,
‘1’ => ‘2001’,
‘2’ => ‘2002’,
‘3’ => ‘2003’,
‘4’ => ‘2004’,
‘5’ => ‘2005’,
‘6’ => ‘2006’,
‘7’ => ‘2007’,
‘8’ => ‘2008’,
‘9’ => ‘2009’,
);

//Week is the next digit following year, specifying weeks 1 through 26.
//Weeks 27 through 52 are designated by the “half” of the year specified above.

$weeks = array(
‘1’ => ‘1’,
‘2’ => ‘2’,
‘3’ => ‘3’,
‘4’ => ‘4’,
‘5’ => ‘5’,
‘6’ => ‘6’,
‘7’ => ‘7’,
‘8’ => ‘8’,
‘9’ => ‘9’,
‘C’ => ’10’,
‘D’ => ’11’,
‘F’ => ’12’,
‘G’ => ’13’,
‘H’ => ’14’,
‘J’ => ’15’,
‘K’ => ’16’,
‘L’ => ’17’,
‘M’ => ’18’,
‘N’ => ’19’,
‘P’ => ’20’,
‘Q’ => ’21’,
‘R’ => ’22’,
‘T’ => ’23’,
‘V’ => ’24’,
‘W’ => ’25’,
‘X’ => ’26’
);

$monthsdays = array(
4 => ’10/01′,
1 => ’01/05′,
2 => ’04/01′,
3 => ’06/20′,
);

$serial = $_GET[‘s’];
$serial = trim(preg_replace(‘/\s+/’, ”, $serial));
$serial_length = strlen($serial);

$output = $_GET[‘o’];
$output = trim(preg_replace(‘/\s+/’, ”, $output));

if ($serial_length == 11) {
//echo “Computer Pre-2012
“;
$year = substr($serial, 2, 1);
$week = substr($serial, 3, 2);
$purchase_year = $years11[$year];
$purchase_week = $week;
} elseif ($serial_length == 12) {
//echo “Computer Post-2012
“;
$year = substr($serial, 3, 1);
$week = substr($serial, 4, 1);
$purchase_year = $years[$year];
$purchase_week = $weeks[$week];
} else {
die(“Nothing to do!”);
}

if(substr($purchase_year, -2,2) == ‘-2′) {
$purchase_week = $purchase_week + 26;
}

$purchase_year = substr($purchase_year, 0, 4);

if ($purchase_week > 36) {
$purchase_term = 1;
$purchase_year++;
} else {
$purchase_term = ceil($purchase_week/12);
}

$purchase_date = $monthsdays[$purchase_term] . “/” . $purchase_year;

if ($output==’csv’) {
echo $serial . ‘,’ . $purchase_date . “\n”;
} elseif ($output==’date’) {
echo $purchase_date . “\n”;
} else {
echo “Manufacture Year: ” . $years[$year] . ” Manufacture Week: ” . $weeks[$week] . “
“;
echo “Year: ” . $purchase_year . ” Term: ” . $purchase_term . ” Purchase Date: ” . $purchase_date;
}

?>

Filed Under: Apple Tagged With: Apple, PHP, Serial Numbers

Partkeepr and PHP 5.6

2015/02/06 By staze

partkeepr-logoBecause I couldn’t find any info on this myself (and therefore my Partkeepr install has been broken since updating to PHP 5.6), and it took the developer of Partkeepr some thought on how to Google for it himself, I thought I would post something quick on Partkeepr and PHP 5.6. Basically, it works, but only if you don’t have a couple options set with PHP 5.6’s Zend OPCache (the built-in OPCache in 5.6, which largely deprecated APC). There are two options for opcache that completely break several frameworks, such as Doctrine, which Partkeepr uses extensively. The options are:

opcache.save_comments
opcache.load_comments

If either of these options is set to “0”, things break. And of course, if you read the notes on “opcache.save_comments” it mentioned breaking Doctrine. So, make sure they’re set to “1” if you’re using any of those frameworks, and especially if you’re using Partkeepr. I banged my head against this for days.

The developer of Partkeepr, however, is going to have a runtime check in a new version that makes sure those two options are set properly, otherwise have Partkeepr throw an error. Here’s the initial bug report of mine. Hopefully this post will help someone, and save them some hair being torn out. =)

UPDATE: I was able to just enable opcache.save_comments and load_comments for just my partkeepr domain by setting:

php_admin_flag opcache.save_comments 1
php_admin_flag opcache.load_comments 1

In the VHOST configuration for apache. This lets me leave them both as 0 for all my other sites, thereby gaining the reduced cached sizes. =) Good luck!

Filed Under: Electronics Tagged With: Partkeepr, PHP

PHP 5.6.4 upgrade (from 5.3.x) and MySQL 5.6

2014/12/31 By staze

PHP-MysqlI’ve been meaning to do this for a while, but a slashdot linked article about the large number of insecure PHP installs in the world got me off my ass to upgrade my stock Mac OS X php install from 5.3.x to 5.6.x. Thankfully, the process was pretty painless with the scripts provided here.

I did have to modify my http conf (since I’m not running a stock Apple install) to point to the new php, as well as set the new install location in my .profile, both of which were pretty easy. The biggest annoyance with the upgrade to PHP 5.6, however, was having to fix anywhere where objects were being set via reference “=&” rather than just =. So most of my PDO DB queries were being set via “$result =& $db->query(‘select blah from blah where blah’)”. This no longer worked with 5.6, as you can only set variables that way. Why I was doing it that way is because I’m a hack, and most of my PHP is copied and pasted from previous PHP I’ve done… so that practice just spread throughout. *shrugs* I also had to adjust some settings relating to APC no longer being supported, and opcache being the new PHP object cache setup. The real big change is, since I use W3TC, I had to DISABLE the Database and Object caches. Since these rely on no-longer supported APC calls, things would work fine for about an hour, then WordPress would just stop responding altogether (guessing when it would try to issue a garbage cleanup call) ((Sadly, the author of this plugin has been rather quiet about adding Zend opcache support)). Interestingly, my site sped up significantly after this change. Cool.

Since my server is a Mac, I had already been running MySQL 5.6 for some time (since OS X doesn’t ship with MySQL anymore), but I wanted to take this opportunity to “upgrade” all my tables from MyISAM to InnoDB. This, actually, was a bit more of a pain than I thought it would be.

[Read more…]

Filed Under: Coding Tagged With: 10.8.5, InnoDB, Mac OS X, Mountain Lion, MyISAM, MySQL, PHP

Next Page »

Weather

Categories / Archives

  • Apple
  • Coding
  • Electronics
  • Energy
  • Home Ownership
  • Miscellany
  • Politics
  • Prius
  • Sys Admin
  • Travel
  • Uncategorized
  • Work
  • June 2026
  • April 2026
  • August 2025
  • April 2025
  • January 2024
  • February 2021
  • July 2020
  • January 2020
  • April 2019
  • March 2018
  • February 2018
  • June 2017

Copyright © 2026 · Staze On Genesis Framework · WordPress · Log in