I have had really bad leg cramps while I sleep since I was really young - about 12 or 13. I had no idea what to do for a long time, so I would pretty much just hope they wouldn't happen. As I got older and they started to leave me feeling sorer and unable to work, etc. I started trying a bunch of stuff.
I started with my dieting first as everyone else does, trying to drink more water and eat more potassium and magnesium. I'm sure it did some help, but the leg cramps would still come and there was nothing I could do to make them go away - sometimes my leg and/or foot would remain cramped for over 5 minutes and I would be forced to practically roll around the room trying to find something that made it finally cease. Usually a certain position or massage, but it never worked fast.
I tried out a product about 6 months ago that claimed it would stop my leg cramps in under a minute and help to prevent them if you take before sleeping. They said it worked well on leg cramps at night, and the product itself was pretty cheap so I tried it. I never really touched the stuff at first because it has a very strong taste, but I took a quick swig of the liquid the first night I woke up with leg cramps after that, and I kid you not the entire episode was stopped in it's tracks. The leg wasn't really sore afterwards because the cramp never really got to set in, and I was able to go right back to bed. I keep a few bottles handy now at all times - best stuff I've ever found online.
The main ingredient is raw apple cider vinegar, and if you look into it like I did you'll find there are quite a few positive traits associated with it besides just leg or foot cramps relief. I recently recommended it to my sister because she was having problems with leg cramps during her pregnancy, and she said it worked for her just the same.