How would a laser gun actually work? So, let's assume that the "laser gun / phaser / beam weapon" from all sorts of Sci Fi were an actual thing.  You know - a weapon that uses a laser to kill somebody.
I'm trying to imagine the physics of such a device, and two issues make me think that the real world physics of the thing make it an impossibility, even if you could get a laser to be that small in reality.


*

*The beam should keep travelling too far to be safe, right?
So, if you fire a normal gun, and miss your target, the bullet continues to travel for a bit. While there is disagreement as to how far, there is still a pretty good reason why you build a firing range against a hill - a stray bullet can still kill at considerable distance.
With light, however, I don't see anything that would stop the beam. If gravity were to affect said beam (and one question I have is, would it?), it would seem that the speed of light, unlike a Star Wars special effect, would mean that the 'bullet' should be able to travel around the entire earth more than 7 times in less than a second. While a bullet is clearly going to hit the ground due to gravity within a space of less than a mile, I wonder, how long would it take a laser beam to dissipate?
Since light has a speed that exceeds escape velocity, I can't see that gravity actually pulls the beam to the ground.  My question is, does the beam continue in a straight line, eventually leaving the atmosphere, and going off into space, or would the curvature of the earth keep the beam orbitting the earth for some time?
And, how far would such a beam go?  At a certain distance, I would assume that orbitting spacecraft would eventually be hit by the beam, or if it closely followed the earth, it seems like the beam would eventually cause a swath of destruction as far as it went.
So, how long would it take for the beam to be dissipated in the air just as a matter of course? 

*The pulse should be way too long to be tactical, right? 
I remember Admiral Grace Hopper showing an 11" bit of wire, and saying that is how far light would travel in a nanosecond.  Her objective, of course, was to show how fast a nanosecond really is.  Applying that to a laser, however, I'm imagining that no computer could actually be fast enough to actually start and stop a laser beam in a nanosecond.
Applying that to a laser gun - and let's assume that it was affected by gravity - means that a normal person triggering a pulse could actually start and stop in 1/8th of a second. Again, at the speed of light, that would mean the pulse should theortically be a long as the circumference of the entire earth at that point, making it tactically impossible to guide in any fashion.
I'm curious what a rational limit would be for a microprocessor would be in terms of time, and then how big of a bolt that would produce.
So, given just these two considerations - length of the bolt in relation to turn on/off times and distance that it would travel, how would a real-world "laser gun" actually work in practice?
 A: The nearest I know of to a real ray gun is the Lockheed ADAM anti-missile laser (see also this popular article or Google for much more on the subject). The Lockheed laser is hardly portable, but who knows what a few centuries of power pack design might achieve and it shows that it can be done.
I don't understand your issue with the length of the laser pulse. Suppose you were aiming a torch at someone: as they move you just turn the torch to follow. Make that torch a gigawatt laser and there's your ray gun.
A: Short answers to both of your points:


*

*Scattering from the air will disperse your beam. How much depends on things like the wavelength and intensity, but that's the main thing that would kill it. Also, it would have to be very collimated, otherwise it will spread naturally and not be very focused when it gets to its destination.

*There are femtosecond lasers, where the entire duration is in that range. Obviously the computer/person controlling it doesn't need to be that quick, though.
A: It sounds like, by citing Admiral Grace Hopper showing that light travels about a foot in a nanosecond, and wondering how to turn a laser on and off within the range of nanoseconds, that you might be wondering if limiting the time that the laser is emitting might limit how far the beam would travel. Firing a laser for just one nanosecond (or any length of time) doesn't stop the pulse it emits from traveling past one foot, since the photons keep traveling past that point if there's nothing in their path to block or slow them down. So far, we haven't figured out how to make a photon travel, by itself, only a certain distance and no further, without using something extraneous to block it, whether a physical object or maybe some type of energy in its path. So if you want your laser blaster beam to stop, you better hit your target.
Also, the movie type of blaster, especially those shown in Star Wars, has an odd characteristic that doesn't seem advantageous, though I don't think this is the kind of feature you're thinking of: the bursts of energy are often shown traveling at a speed slow enough to allow us to track them with our eyes.  While this is a cinematic thing to allow us to relate to these weapons as we do to bullet-based weapons (or arrows, I guess), it would be a disadvantage in real combat since it would often give a person who's the target enough time to get out of the way if they move fast enough, and this is what we see in many SF films that use them.  A beam that always travels at the speed of light, until it hits its target, would be harder to avoid.
But since your question involves speculating on a type of technology that can distance-limit an energy beam, it seems reasonable to offer speculation about how we might be able to get it to work using possible developments and our understanding of physics.  Since you're certainly thinking of a self-contained weapon, anything that serves to limit the distance the energy beam can travel has to be incorporated in the weapon itself, instead of some extraneous object or force.  If we could generate some kind of "blocking energy" that could stop the energy beam, but which wouldn't have the force of the energy beam, it might be possible for the weapon to simultaneously send a beam of that blocking energy, traveling almost in parallel with the energy beam, but intersecting it at the desired cutoff distance, with the angle of the blocking beam (or maybe the energy beam) adjusted maybe by a rangefinder that determines the distance to the target, so that the two beams intersect preferably somewhere inside the target or just at its rear surface.  Maybe you could have a ring of energy beam emitters, or a full emitter ring, around the circumference of the flat front end of the "barrel", and an emitter for the blocking energy in the center of the energy beam that travels as a long, expanding cone that intersects with the energy beam to block it at the desired distance.  If this could be gotten to work, the weapon might be more like a Star Wars lightsaber with a variable-length shaft or beam, rather than something that shoots a visibly moving burst of light.
