gmp_strval($r, 16) may return less then 64 characters in length. if this is the case then parsing the signature may break.
I fixed that issue by appending zeros at the left.
return str_pad(gmp_strval($r, 16), 64, "0", STR_PAD_LEFT) . str_pad(gmp_strval($s, 16), 64, "0", STR_PAD_LEFT);