PHP serial commands work only when serial monitor is open

PS: I am using custom hardware so its not a auto reset problem

Can you explain why that is the case? please post the schematics so we can verify ..

If you use another terminal program, do you see the same effects?
If so it can be "in the driver" of the serial port.