To stop apache from consuming more cpu you can enter the limitations on it,

use the below parameter on values you need,

RLimitCPU 50, 100

50,100 is  softlimit and a hard limit in seconds

This would prevent the run away scripts from taking down the server.