I find it hard to work out how to really use this reliably particularly in respect to collisions.
It maps to SysV IPC msgget.
As I see it you have three options...
1. Manage the IDs yourself, allocating various ranges or using some kind of centralised mechanism.
2. Use ftok. This attempts to find a unique ID, though it's not guaranteed to be unique or constant in absolutely every circumstance. It relies on using a file, from which it uses bits from the inode and dev it expects to be unique. It's the standard way and as long as there's nothing too unusual it should probably work (but might not survive radical FS changes).
3. Use 0 as the key, which appears to map to IPC_PRIVATE, a magic value which if provided as a key creates a new queue each time (without a key in effect).
Unfortunately option #3 is of limited use in PHP.
In C that is useful might be useful as the queue resource is just identified by an int and can be passed around.
In PHP its utility is questionable as only the resource can be passed within a single process. It's not possible to pass the resource with serialize / unserialize even though it's just a wrapped int.
The msqid returned isn't exactly unpredictable either so can quite easily be accidentally accessed. The first one I got was 0.
If you create a queue like this you'll find it very annoying as it wont be possible to delete it via PHP.
Like all IO it's worth wrapping this function and launching an exception if the input is 0.