I have been taking a half a Prilosec for years. Is it harmful? If I stop, within a few days I have really bad heartburn.

Maybe. Maybe ask why do you have more acid? Often when pancreas doesn't produce sufficient enzymes to digest food then stomach secretes more acid to "make up" causing heartburn. Acid is needed to absorb many nutrients among other important functions god intended. Long term suppression is not good. Try some good digestive enzymes with meals and then try to taper Prilosec for long term health preservation.
Yes some risks. Long term use of Prilosec has been reported to increase risks of bone fractures, liver damage, and esophageal yeast infections. It may also interact with other medications that you might have added to your regimen and the risks go up with age. Here is a review http://www.Livestrong.Com/article/191389-the-effects-of-long-term-usage-of-prilosec/.