Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function handle_connection($sock) {
  2. global $agi;
  3.  
  4. $msgsock = socket_accept($sock);
  5. $pid=pcntl_fork();
  6. if ($pid == 0) {
  7. pcntl_signal(SIGHUP,SIG_IGN);
  8. pcntl_signal(SIGTERM,SIG_IGN);
  9. // pcntl_signal(SIGHUP,"handle_signal");
  10. require_once("/var/lib/asterisk/agi-bin/phpagi/phpfastagi.php");
  11. $agi=new AGI($msgsock);
  12. $var=$agi->request['agi_network_script'];
  13. $agiurl=parse_url($var);
  14. parse_str($agiurl['query']);
  15. if (isset($agiurl['path'])) {
  16. require_once("/var/lib/asterisk/agi-bin/" . $agiurl['path']);
  17. }
  18. socket_close($msgsock);
  19. exit;
  20. } else {
  21. pcntl_signal(SIGCLD,SIG_IGN);
  22. pcntl_signal(SIGHUP,SIG_IGN);
  23. }
  24. }
  25.  
  26. $sock=socket_create(AF_INET,SOCK_STREAM,0);
  27.  
  28. if ($_SERVER['argv'][1] != "" ) {
  29. socket_bind($sock,$_SERVER['argv'][1],$port) or die("Bind Failed\n");
  30. } else {
  31. socket_bind ($sock,$address,$port) or die("Bind Failed\n");
  32. }
  33.  
  34. socket_listen($sock,128);
  35.  
  36.  
  37. if (pcntl_fork() == 0) {
  38. pcntl_signal(SIGCLD,SIG_IGN);
  39. while(true) {
  40. handle_connection($sock);
  41. }
  42. } else {
  43. exit;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement