I have the problem that I will have multiple servers that perform jobs. They all request a joblist from the same API and need to identify them with a unique id. So that I know which server is running which jobs and have no distribution collisions etc.
I am now trying to figure out a way to generate a unique server id. It is not critical that it stays the same forever. But it should be unique.
I noticed the PHP build time in phpinfo() but couldn't find any documentation about it. What if php is installed as a binary package? It will probably not change if two servers use the same package.
I would prefer some sort of mother board serial number or something.
A yeah, and it should be portable. So I would rather like to avoid something like calling a shell command using shell_exec or so.
Going for the external IP could also be an option. But how to reliably determine the "external" ip adress? what if there are more? What if its natted? Then i would need a combination of external and internal adress.
I could request the API one time and ask it to give me the external ip adress and combine. But this is going way to complicated and extensive...
Do you have any recommendations on this?
I would say give them an Id.
Your server is the master, build a protocol, if the server is not giving you is unique Id in the sent query then build a new record for this new server and give him the record id. Then Your protocol on the joblist query state that the client server should now reuse the given Id. if he does not he will get a new id each time (which is unique).
You'll face the problem, maybe, of a growing number of Id, then add a TTL to each Id, and perform some cleanup (or simply wipe out this table sometimes). In your protocol you should now at a way to tell your client server his given Id has been invalidated and that you give him a new one.
If you really want to delegate this 'unique Id' management to the clients, then ask them to generate a random uid, and prey that it do not collide (very low %, but it can happen, but maybe not before you die). You'll have to store it on your sied, and manage the growing number of Id as well. But there you will simply take the server given Id as a new one after wipeout, you don't need to ask client to rebuild a new Id. Simplier.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki