23 lines
981 B
Python
23 lines
981 B
Python
#!/usr/bin/env python3
|
|
path = "/var/www/html/api/nonreg-master.php"
|
|
with open(path, "rb") as f:
|
|
raw = f.read()
|
|
|
|
if b"usleep(800000)" in raw:
|
|
print("ALREADY_PATCHED")
|
|
exit(0)
|
|
|
|
# Insert usleep(800ms) inside api() function before curl_exec
|
|
# This prevents back-to-back saturation of FPM workers
|
|
old = b"curl_setopt_array($ch,[\n CURLOPT_POST=>1,CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>$to,"
|
|
new = b"// V77: throttle to prevent FPM worker saturation on rapid-fire calls\n static $lastCall = 0;\n $now = microtime(true);\n if ($lastCall > 0 && ($now - $lastCall) < 0.8) { usleep((int)((0.8 - ($now - $lastCall)) * 1000000)); }\n $lastCall = microtime(true);\n curl_setopt_array($ch,[\n CURLOPT_POST=>1,CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>$to,"
|
|
|
|
if old not in raw:
|
|
print("OLD_NOT_FOUND")
|
|
exit(1)
|
|
|
|
new_raw = raw.replace(old, new, 1)
|
|
with open(path, "wb") as f:
|
|
f.write(new_raw)
|
|
print(f"PATCHED {len(raw)} -> {len(new_raw)}")
|