在Laravel5.1中请求ajax文件不控制PHP?

在Laravel5.1中请求ajax文件不控制PHP?,php,ajax,laravel,post,Php,Ajax,Laravel,Post,我有一个自己的文件,用于接收post请求ajax,但请求从未出现 在视图中: <script type="text/javascript"> $(document).ready(function(){ $("#bloquear").click(function(e){ $.post("proyectodam/app/Lib/ServerSocket.php", {op: 1}); }); }); </scr

我有一个自己的文件,用于接收post请求ajax,但请求从未出现

在视图中:

<script type="text/javascript">
    $(document).ready(function(){
        $("#bloquear").click(function(e){
            $.post("proyectodam/app/Lib/ServerSocket.php", {op: 1});
        });
    });
</script>
    <?php 
namespace proyectodam\Lib;

try{
    set_time_limit(0);
    $address = '127.0.0.1';
    $port = 5555;
    // Create a TCP Stream socket
    $sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for  SQL_TCP
    // Bind the socket to an address/port
    socket_bind($sock, $address, $port) or die('Could not bind to address');  //0 for localhost
    // Start listening for connections
    socket_listen($sock);
    //loop and listen
    while(true){
      /* Accept incoming  requests and handle them as child processes */
      $client = socket_accept($sock);
      //$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);
      // Read the input  from the client – 1024000 bytes
      //$input = socket_read($client, 1024000);
      // from here you need to do your database stuff
      // and handle the response 

       // Display output  back to client
      if(isset($_POST["op"])){
          $message = 1;
          socket_write($client, $message, strlen($message));
      }
      socket_close($client);
    }
    // Close the master sockets
    socket_close($sock);
}catch(Exception $e){
    echo 'Excepción capturada: ',  $e->getMessage(), "\n";
}
文件PHP:

<script type="text/javascript">
    $(document).ready(function(){
        $("#bloquear").click(function(e){
            $.post("proyectodam/app/Lib/ServerSocket.php", {op: 1});
        });
    });
</script>
    <?php 
namespace proyectodam\Lib;

try{
    set_time_limit(0);
    $address = '127.0.0.1';
    $port = 5555;
    // Create a TCP Stream socket
    $sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for  SQL_TCP
    // Bind the socket to an address/port
    socket_bind($sock, $address, $port) or die('Could not bind to address');  //0 for localhost
    // Start listening for connections
    socket_listen($sock);
    //loop and listen
    while(true){
      /* Accept incoming  requests and handle them as child processes */
      $client = socket_accept($sock);
      //$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);
      // Read the input  from the client – 1024000 bytes
      //$input = socket_read($client, 1024000);
      // from here you need to do your database stuff
      // and handle the response 

       // Display output  back to client
      if(isset($_POST["op"])){
          $message = 1;
          socket_write($client, $message, strlen($message));
      }
      socket_close($client);
    }
    // Close the master sockets
    socket_close($sock);
}catch(Exception $e){
    echo 'Excepción capturada: ',  $e->getMessage(), "\n";
}

失败?

如果您向
proyectodam/app/Lib/ServerSocket.php
发出post请求,您需要确保在
/public/proyectodam/app/Lib/ServerSocket.php

但是,我建议您做一个api端点,例如:

Route::post('socket', function() {
    return new ClientSocket();
}
然后将客户端套接字库类设置为:

<?php 
namespace proyectodam\Lib;

class ClienteSocket {

public function __construct() 
{
  try{
    set_time_limit(0);
    $address = '127.0.0.1';
    $port = 5555;

    // Create a TCP Stream socket
    $sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for  SQL_TCP

    // Bind the socket to an address/port
    socket_bind($sock, $address, $port) or die('Could not bind to address');  //0 for localhost

    // Start listening for connections
    socket_listen($sock);

    //loop and listen
    while(true){
        /* Accept incoming  requests and handle them as child processes */
        $client = socket_accept($sock);

        //$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);

        // Read the input  from the client – 1024000 bytes
        //$input = socket_read($client, 1024000);
        // from here you need to do your database stuff
        // and handle the response 

        // Display output  back to client
        if(isset($_POST["op"])){
            $message = 1;
            socket_write($client, $message, strlen($message));
        }
        socket_close($client);
    }

    // Close the master sockets
    socket_close($sock);
  } catch(Exception $e){
    echo 'Excepción capturada: ',  $e->getMessage(), "\n";
  }
}
}

如果您向
proyectodam/app/Lib/ServerSocket.php
发出post请求,您需要确保在
/public/proyectodam/app/Lib/ServerSocket.php

但是,我建议您做一个api端点,例如:

Route::post('socket', function() {
    return new ClientSocket();
}
然后将客户端套接字库类设置为:

<?php 
namespace proyectodam\Lib;

class ClienteSocket {

public function __construct() 
{
  try{
    set_time_limit(0);
    $address = '127.0.0.1';
    $port = 5555;

    // Create a TCP Stream socket
    $sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for  SQL_TCP

    // Bind the socket to an address/port
    socket_bind($sock, $address, $port) or die('Could not bind to address');  //0 for localhost

    // Start listening for connections
    socket_listen($sock);

    //loop and listen
    while(true){
        /* Accept incoming  requests and handle them as child processes */
        $client = socket_accept($sock);

        //$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);

        // Read the input  from the client – 1024000 bytes
        //$input = socket_read($client, 1024000);
        // from here you need to do your database stuff
        // and handle the response 

        // Display output  back to client
        if(isset($_POST["op"])){
            $message = 1;
            socket_write($client, $message, strlen($message));
        }
        socket_close($client);
    }

    // Close the master sockets
    socket_close($sock);
  } catch(Exception $e){
    echo 'Excepción capturada: ',  $e->getMessage(), "\n";
  }
}
}

您是否确保可以从浏览器访问
proyectodam/app/Lib/ServerSocket.php
位置/文件?我想您的问题没有说太多,但为什么不将文件包含到路由控制器中?我的文件php是一个服务器套接字,它在命令行上运行,我需要从a发送信息给verver,然后这个给客户端pd:我设法将客户端与服务器连接,但我没有工作,我的客户端部分是Java的,您是否确保可以从浏览器访问
proyectodam/app/Lib/ServerSocket.php
location/file?我想您的问题没有说太多,但为什么不将该文件包含到路由控制器中?我的文件php是一个服务器套接字,它在命令行上运行,我需要从a向verver发送信息,并将其发送给客户机pd:我设法将客户机与服务器连接。我没有工作,我有javanot errors中的客户机部分,我没有收到请求ajax到服务器的数据。如果没有错误,那么问题出在哪里。听起来可能不是laravel的问题,而是您实际使用的脚本的问题。您要放置的客户端套接字是服务器套接字,我的客户端是Java的。我需要一个功能示例,我被这个问题逼得绝望:(不是错误,我没有收到服务器请求ajax的数据如果没有收到错误,那么问题出在哪里。听起来可能不是laravel的问题,而是您实际使用的脚本的问题。您要放置的客户端套接字是服务器套接字,我的客户端是Java。我需要一个功能示例,我感到绝望通过这个问题:(