Memory limitation comes from the OS, not from PHP itself.
Your script allocated 800MB and is trying to allocate further 500MB
Try to run the script on 64bit OS with 64 bit PHP.