Coherent Phase Control of Ultrashort Electron Pulses by Traveling Optical Waves and Whispering-gallery Modes