I have written following function in functions.php file and trying to access it through jquery ajax.

This works fine.

function data_fetch(){
    var_dump($_POST);
    echo "working";
}

But this doesn't show any error and prints nothing

function data_fetch(){
//  var_dump($_POST);
    echo "working";
    $host    = "x.x.x.x";
    $port    = 35001;
    $message = json_encode($_POST);
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
    $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");  
    socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
    $result = socket_read ($socket, 1024) or die("Could not read server response\n");
    echo "Reply From Server  :".$result;
    socket_close($socket);
}

is this way right? if no then what are another way to do socket programming with WordPress?

  • There must be an error somewhere. Have you checked the web server logs? – Rup Jun 18 '17 at 11:44
  • 1
    in log it says that call to undefined function socket_create() but i have enabled sockets in my php ini file – JAGGADAKU Jun 18 '17 at 17:02

The answer is "No", there is nothing in wordpress that may interfere with usage of PHP socket API.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.