0

So, I considered asking here instead of SO because people here are more likely to be familiar with this stuff.

I'm currently using PHP to detect some generic stuff on the host OS. In this case, I'm trying to detect CPU vendor.

To do this, I have:

  • linux: execute('grep -m 1 vendor_id /proc/cpuinfo')
  • windows: getenv('PROCESSOR_IDENTIFIER')
  • osx: ???

OSX is indeed my problem. I don't have a test machine, and I refuse to run an illicit VM (I already am using 11 legit VMs).

So, since Apple makes it impossible to do this without spending nothing less than $500 to be able to run osx, I've decided to resort to someone else to help me achieve this.

I'd like the command to work on both PPC and Intel models.

Related Thread on SO again, I'm not able to run any of those commands.

4 Answers 4

2

Try this from the terminal or execute as needed:

system_profiler|grep Processor

Sample:

> dmourati$ system_profiler|grep Processor
>       Processor Name: Intel Core 2 Duo
>       Processor Speed: 2 GHz
>       Number Of Processors: 1
2
  • Sounds great! Can grep be made to read from after Processor Name: till the next newline? Also, if someone could test this on a PPC and verify that it works, it would be great.
    – Christian
    Jul 28, 2011 at 6:57
  • 2
    system_profiler|grep Processor | sed 's/Processor Name: //'
    – user9517
    Jul 28, 2011 at 7:10
1

A faster way then the previous post:

system_profiler SPHardwareDataType | grep Processor\ Name

That limits it to only scanning the hardware, which is faster than scanning the whole system.

You can also change the first command to system_profiler -xml SPHardwareDataType if you want to read it in as XML and parse it that way (which should be more stable if the output changes from version-to-version.

1
  • Thanks, SPHardwareDataType did some great improvement in speed.
    – Christian
    Jul 28, 2011 at 7:42
0

I'm answering my question because I got to the best fit answer, but not without the help of the two people above. So, thanks a lot guys.

Note: There's an additional command, because I found out that on the old PPC version, there's no "Processor Name", but instead, it is "CPU Type". Command system_profiler SPHardwareDataType | grep CPU\ Type fixed the problem. I just switch to it if the suggested one doesn't yield results.

Here's the code:

// ...
case 'osx':
    // check on OSX
    $res=self::execute('system_profiler SPHardwareDataType | grep Processor\ Name');
    $procid=trim(strtolower($res['stdout']));
    if($procid==''){ // for older PPC-based models
        $res=self::execute('system_profiler SPHardwareDataType | grep CPU\ Type');
        $procid=trim(strtolower($res['stdout']));
    }
    break;
// ...

// match vendor
if(strpos($procid,'intel')  !==false)return 'intel';
if(strpos($procid,'amd')    !==false)return 'amd';
if(strpos($procid,'ppc')    !==false)return 'ppc';
if(strpos($procid,'powerpc')!==false)return 'ppc';

Dependency Note

I'm using a custom function for executing commands. It returns an array of result, stdout, stderr among other things. In this case, only stdout is being used, so you can as well replace it with shell_exec().

0

sysctl will dump the info you need:

sysctl -a | grep cpu

Example output on a 2018 15" MacBook Pro:

hw.ncpu: 12
hw.activecpu: 12
hw.cpu64bit_capable: 1
hw.cpufamily: 260141638
hw.cpufrequency: 2900000000
hw.cpufrequency_max: 2900000000
hw.cpufrequency_min: 2900000000
hw.cpusubfamily: 0
hw.cpusubtype: 8
hw.cputype: 7
hw.logicalcpu: 12
hw.logicalcpu_max: 12
hw.physicalcpu: 6
hw.physicalcpu_max: 6
hw.cputhreadtype: 1
machdep.xcpm.cpu_thermal_level: 82
machdep.cpu.xsave.extended_state: 31 832 1088 0
machdep.cpu.xsave.extended_state1: 15 832 256 0
machdep.cpu.tlb.data.small: 64
machdep.cpu.tlb.data.small_level1: 64
machdep.cpu.tlb.inst.large: 8
machdep.cpu.thermal.ACNT_MCNT: 1
machdep.cpu.thermal.core_power_limits: 1
machdep.cpu.thermal.dynamic_acceleration: 1
machdep.cpu.thermal.energy_policy: 1
machdep.cpu.thermal.fine_grain_clock_mod: 1
machdep.cpu.thermal.hardware_feedback: 0
machdep.cpu.thermal.invariant_APIC_timer: 1
machdep.cpu.thermal.package_thermal_intr: 1
machdep.cpu.thermal.sensor: 1
machdep.cpu.thermal.thresholds: 2
machdep.cpu.mwait.extensions: 3
machdep.cpu.mwait.linesize_max: 64
machdep.cpu.mwait.linesize_min: 64
machdep.cpu.mwait.sub_Cstates: 286531872
machdep.cpu.cache.L2_associativity: 4
machdep.cpu.cache.linesize: 64
machdep.cpu.cache.size: 256
machdep.cpu.arch_perf.events: 0
machdep.cpu.arch_perf.events_number: 7
machdep.cpu.arch_perf.fixed_number: 3
machdep.cpu.arch_perf.fixed_width: 48
machdep.cpu.arch_perf.number: 4
machdep.cpu.arch_perf.version: 4
machdep.cpu.arch_perf.width: 48
machdep.cpu.address_bits.physical: 39
machdep.cpu.address_bits.virtual: 48
machdep.cpu.tsc_ccc.denominator: 2
machdep.cpu.tsc_ccc.numerator: 242
machdep.cpu.brand: 0
machdep.cpu.brand_string: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
machdep.cpu.core_count: 6
machdep.cpu.cores_per_package: 8
machdep.cpu.extfamily: 0
machdep.cpu.extfeature_bits: 1241984796928
machdep.cpu.extfeatures: SYSCALL XD 1GBPAGE EM64T LAHF LZCNT PREFETCHW RDTSCP TSCI
machdep.cpu.extmodel: 9
machdep.cpu.family: 6
machdep.cpu.feature_bits: 9221959987971750911
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C
machdep.cpu.leaf7_feature_bits: 43806655 1073741824
machdep.cpu.leaf7_feature_bits_edx: 2617257472
machdep.cpu.leaf7_features: RDWRFSGS TSC_THREAD_OFFSET SGX BMI1 HLE AVX2 SMEP BMI2 ERMS INVPCID RTM FPU_CSDS MPX RDSEED ADX SMAP CLFSOPT IPT SGXLC MDCLEAR TSXFA IBRS STIBP L1DF SSBD
machdep.cpu.logical_per_package: 16
machdep.cpu.max_basic: 22
machdep.cpu.max_ext: 2147483656
machdep.cpu.microcode_version: 234
machdep.cpu.model: 158
machdep.cpu.processor_flag: 5
machdep.cpu.signature: 591594
machdep.cpu.stepping: 10
machdep.cpu.thread_count: 12
machdep.cpu.vendor: GenuineIntel

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .