The best way to do this is the same way you should do ajax within MODx. Put all of your php code into a snippet in a dedicated resource, use the MODx api wherever possible, then reference that resource as your EventSource in JS:
// eg. put your snippet in resource '6'
var source = new EventSource('[[~6]]');