Skip to content

Instantly share code, notes, and snippets.

@rdlowrey
rdlowrey / cpu-core-count.php
Created February 20, 2015 14:50
OS-generalized CPU counting
<?php
function countCpuCores() {
$os = (stripos(PHP_OS, "WIN") === 0) ? "win" : strtolower(trim(shell_exec("uname")));
switch ($os) {
case "win":
$cmd = "wmic cpu get NumberOfCores";
break;
case "linux":
$cmd = "cat /proc/cpuinfo | grep processor | wc -l";
break;
@rdlowrey
rdlowrey / strict-scalars.php
Last active August 29, 2015 14:15
Are you *sure* you don't need strict scalar typehints?
<?php
$ch = curl_init();
// 1: only verify that the peer cert HAS a name field
// 2: verify that the name ACTUALLY matches the domain you connected to
// true: cast to 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
// Mercifully the newest versions of libcurl now disable 1 for this setting.
// This is a prime example of undetectable scalar conversion catastrophe.
@rdlowrey
rdlowrey / php56-ssl-tls-improvements.md
Created February 16, 2014 17:07
SSL/TLS improvements in PHP 5.6

[RFC] TLS Peer Verification

  • Verify peer certificates in client streams by default
  • Use operating system managed default cert stores if not otherwise specified
  • Windows is still an issue as it uses different cert format (I'm working on it)

[RFC] Improved TLS Defaults

  • Makes everything SSL/TLS more secure without any user knowledge required
  • Vastly improved support for encrypted stream servers (a-la node.js)