Executing PHP code only once, when the node is created
You should use hook_node_insert in a custom module to run your code when the node is created.

function hook_node_insert($node) {
  // To include @marcvangend's comment.
  if ($node-&gt;type == 'type') {
    // Run code here only for node of type 'type'.
  }
  // Run code here for all nodes...
}