PHP - Readport issues

I think that for the moment is better use sleep time, but how know many time I've to sleep ? how I can sure that I received back the message on my php page in the right moment ? and the rest of the php code i think is correct ... fixed this I think that I can start to understand better how it's working thanks for the support ...

I've tried to put sleep(1) between send data and readport, but still to have the variable void ... :frowning:

Andrea