CURLOPT_LOCALPORT has a random value by default. I checked the easybitcoin code and didn't find the option, so it should be ok.
Are you sure the port is bond by apache, but not the wallet itself (or previous instance of the wallet)? Is the problem only happens when restarting the wallet? In my Linux box, after a wallet quits, the ports will still be unavailable for some time (2 minutes by default), with some connections remain 'TIME_WAIT' state. You can check it with 'netstat -an | grep YOUR_PORT'. I don't know if it's a bug of the wallet or it's a feature of Linux though (whether the wallet properly closes all connections before quit). If it's a feature of Linux, it's possible to tweak via 'sysctl' utility:
sysctl net.ipv4.tcp_tw_reuse = 1
sysctl net.ipv4.tcp_tw_recycle = 1
Be careful while tweaking kernel options. It may cause other problems occasionally.
If you have iptables/netfilter loaded into the kernel, you may have interest to try:
sysctl net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 1It means every connection will stay in 'TIME_WAIT' state for only one second. Again, be careful.
Another solution could be wait for 2 minutes after the wallet quits, before a restart.
Or change the listening port number every time (and let the php program know it).
BTW does anybody know whether it's necessary for the wallet to check connections in TIME_WAIT state before bind/listen to the port?