I Got it.
As you described, your system is supposed to check on some numbers status and on change update it.
I thing I found a problem on this script is that it is inserting a new pair of number and status and when it recovers it again to check it it will probably get the first one again, not the last one you inserted, as it is not updating it but creating a new record. That may be one of the big issues.
The script it self can be improved by caching values (as long as the expected change does not occurs on the MySQL).
Other possible improvement, if the change occurs some place else, is to cache the values on the JavaScript code.