Run some tests.
Try another device on your WiFi network, and see if the same problem occurs with your iPhone on the other network.
Use your iPhone at the local Apple store or on another WiFi network, and see if the problem occurs there.
If you have similar problems on another network, then you may have a problem with WiFi or iOS on your iPhone.
Otherwise, there's a chance of WiFi interference or other problems on your network or with your ISP connection or problems with the local network's DHCP settings for DNS services (bad or buggy DNS servers can cause flaky connections), or there are potentially problems with your WiFi router or access point.