Are you uniquing PHP arrays using array_unique? Consider doubling up with array_flip instead. Array_unique is pretty slow.