The more closer the gas port is to the muzzle, the more pressure you'll get which in turn increase the reliability. But also increase the heat transfer, fouling and recoil.
On other hand, the farther the gas port will be, the softer shooting the gun will be, with low fouling and heat transfer. But again the cost here will be low reliability as the gun will often encounter a malfunction called "short stroking"
So the location of gas port is usually a balance point between these two extremes.