public static function phpEcRecover(string $message_hash, string $signature)
    {
        $return = NULL;

        $ec = new EC('secp256k1');
        $sign   = ["r" => substr($signature, 2, 64), "s" => substr($signature, 66, 64)];
        $recid  = ord(hex2bin(substr($signature, 130, 2))) - 27;

        $pubKey = $ec->recoverPubKey($message_hash, $sign, $recid);

        $recoveredAddress = "0x" . substr(Keccak::hash(substr(hex2bin($pubKey->encode("hex")), 1), 256), 24);
        return $recoveredAddress;
    }
public static function phpEcRecover(string $message_hash, string $signature)
    {
        $return = NULL;

        $ec = new EC('secp256k1');
        $sign   = ["r" => substr($signature, 2, 64), "s" => substr($signature, 66, 64)];
        $recid  = ord(hex2bin(substr($signature, 130, 2))) - 27;

        $pubKey = $ec->recoverPubKey($message_hash, $sign, $recid);

        $recoveredAddress = "0x" . substr(Keccak::hash(substr(hex2bin($pubKey->encode("hex")), 1), 256), 24);
        return $recoveredAddress;
    }
public static function phpEcRecover ( string $ message_hash , string $ signature ) { $ return = NULL ; $ ec = new EC ( 'secp256k1' ) ; $ sign = [ "r" => substr ( $ signature , 2 , 64 ) , "s" => substr ( $ signature , 66 , 64 ) ] ; $ recid = ord ( hex2bin ( substr ( $ signature , 130 , 2 ) ) ) - 27 ; $ pubKey = $ ec -> recoverPubKey ( $ message_hash , $ sign , $ recid ) ; $ recoveredAddress = "0x" . substr ( Keccak :: hash ( substr ( hex2bin ( $ pubKey -> encode ( "hex" ) ) , 1 ) , 256 ) , 24 ) ; return $ recoveredAddress ; }
EcRecover - Elliptic Curve Signature Verification.

This function ecRecover is a wrapper to a solidity function (ececover).
See:
http://solidity.readthedocs.io/en/latest/miscellaneous.html?highlight=ecrecover

Using this ecRecover-wrapper it is the recommended to use ecrecover in
order to  provide future performance improvements.

EC recovery doses not require any blockchain interaction, it's just
freaky math. Considering libraries, PHP extensions or command
line C or node implementations.

@param string $message_hash .
Keccak-256 of message in hex

@param string $signature .
Keccak-256 of message in hex

@return string
Keccak256 of the provided string.

@throws \Exception
If keccak hash does not match formal conditions.
EcRecover - Elliptic Curve Signature Verification .