How can I swallow a whole cockatrice?
You need to use an engulfing attack on the cockatrice. Purple worms have both a Bite attack and an Engulf attack. My guess is that since it seems like you used the Bite attack, the bite caused you to be petrified before you had a chance to actually engulf the cockatrice.
As an alternative, trappers and lurkers above will also work, as their sole attack is an engulf attack. (Lots of other monsters have engulfing attacks as well, but everything aside from the aforementioned three types are petrification-resistant, which you obviously don't want for this.)