This is incorrect. If the goal is to all the local extension and then dialout to the PSTN then this is completely backwards, plus the Exten setting is completely wrong. This is what it should look like:
fwrite($socket, "Channel: $ext@originate-skipvm\r\n");
fwrite($socket, "Exten: $did\r\n");
fwrite($socket, "Context: from-internal\r\n");
fwrite($socket, "Priority: 1\r\n");
Remember Exten, Context, Priority are used together. So the original originate would end up looking like when tryng to connect to Exten/Context/Priority…from-internal,$ext@originate-skipvm,1
< this is how Asterisk would put it together and it would fail.
Document for AMI Event: Originate - Asterisk Documentation