Php-linux-environment-development-Pusher in Linux

Source: Internet
Author: User
Recently, when I made a new website for bounty hunters, I wanted to use Pusher to make a comments on the homepage. After I tested it locally, I deployed it on Linux, however, after opening it, you can find that messages cannot be sent. When you open the Pusher console, the information is displayed as a channel connection, but the message is sent...

Recently, when I made a new website for bounty hunters, I wanted to use Pusher to make a comments on the homepage. After I tested it locally, I deployed it on Linux, however, after opening the message, it is found that the message cannot be sent. When the Pusher console is opened, the information is displayed as a channel connection, but the message sending event is not executed. I open the local file (the local file and the deployment file use the same Pusher application), and the local file can be displayed on the deployed file. I haven't found the problem for a long time.

The structure of the entire project is as follows:

main.jsFile Content:

(function($){    var pusher  = new Pusher('18f9924cb7ee44a01ec0'),        channel = pusher.subscribe('imgondar');    Pusher.log = function( msg ) {        if( console && console.log ) {            console.log( msg );        }    };    channel.bind('send_message', function (data) {        Snarl.addNotification({            title: data.name,            text: data.msg,            timeout: 5000        });    });    $('form').submit(function(){        var say = $('#message').val();        if ( say ) {            $.post('post.php', $(this).serialize());            $('#message').val('').focus();        }        return false;    });})(jQuery);

post.phpFile Content:


  Htmlentities (getName (). ':'), 'msg '=> htmlentities (strip_tags ($ _ REQUEST ['message']),); $ pusher-> trigger ('imgondar ', 'Send _ message', $ data); function getName () {$ name_array = array (0 => "Dragon girl", 1 => "Yang Guo ", 2 => "Jin Yong", 3 => "Guo Jing", 4 => "Huang Rong", 5 => "Ouyang Feng", 6 => "Duan Yu ", 7 => "", 8 => "", 9 => "Mu Chen", 10 => "Java", 11 => "JavaScript ", 12 => "Python", 13 => "C ++", 14 => "HTML", 15 => "what a ghost ~~ ", 16 =>" cannot think of ^ ", 17 =>" a column ", 18 =>" just want to vomit ", 19 =>" Lu Ren jia ", 20 => "passers-by B", 21 => "Runner-up", 22 => "main character", 23 => "I am a female", 24 => "I am just a slave ", 25 => "Please call me Rong ma", 26 => "I will drop the 18 th palm of the Dragon", 27 => "", 28 => "speechless! -_-", 29 =>" Qiao Feng ", 30 =>" bad guy ",); $ index = rand (0, count ($ name_array)-1 ); return $ name_array [$ index];}

Visit the local http: // 127.0.0.1/imgondarv8_test/and click send. The following results are displayed in the browser:

Because I havemain.jsIn the code, let it output logs and open the browser console to see:

Open the Pusher console:

Now the problem arises. I deployed the code to the Linux server through svn and accessed it through the following Domain Name:
Http://testgondar.helloarron.com/

Clicking "send" does not work. The Pusher console and browser console information are as follows:


Although the connection is established, the message is not sent successfully.

However, I use the local http: // 127.0.0.1/imgondarv8_test/to send messages and receive messages (after all, the same Pusher application is used ), display the received information in the browser console:

After testing for half a day, it's in post. php.$pusher->trigger('imgondar', 'send_message', $data);Not executed in Linux.

ViewPusher.phpFiletriggerFunction:

public function trigger ( $channel, $event, $payload, $socket_id = null, $debug = false, $already_encoded = false ){    $ch = curl_init();    if ( $ch === false ){        die( 'Could not initialise cURL!' );    }    # Add channel to URL..    $s_url = $this->settings['url'] . '/channels/' . $channel . '/events';    # Build the request    $signature = "POST\n" . $s_url . "\n";    $payload_encoded = $already_encoded ? $payload : json_encode( $payload );    $query = "auth_key=" . $this->settings['auth_key'] . "&auth_timestamp=" . time() . "&auth_version=1.0&body_md5=" . md5( $payload_encoded ) . "&name=" . $event;    # Socket ID set?    if ( $socket_id !== null ){        $query .= "&socket_id=" . $socket_id;    }    # Create the signed signature...    $auth_signature = hash_hmac( 'sha256', $signature . $query, $this->settings['secret'], false );    $signed_query = $query . "&auth_signature=" . $auth_signature;    $full_url = $this->settings['server'] . ':' . $this->settings['port'] . $s_url . '?' . $signed_query;    # Set cURL opts and execute request    curl_setopt( $ch, CURLOPT_URL, $full_url );    curl_setopt( $ch, CURLOPT_HTTPHEADER, array ( "Content-Type: application/json" ) );    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );    curl_setopt( $ch, CURLOPT_POST, 1 );    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload_encoded );    curl_setopt( $ch, CURLOPT_TIMEOUT, $this->settings['timeout'] );    $response = curl_exec( $ch );    curl_close( $ch );    if ( $response == "202 ACCEPTED\n" && $debug == false ){        return true;    } elseif ( $debug == true || $this->settings['debug'] == true ) {        return $response;    } else {        return false;    }}

I think it may be that the php environment in linux is not enabled.curlModule, so I wrote a simple example of capturing the Baidu homepage and foundcurlYes. I can't find any other reason, and ask the experts to offer support. Thank you ^

Reply content:

Recently, when I made a new website for bounty hunters, I wanted to use Pusher to make a comments on the homepage. After I tested it locally, I deployed it on Linux, however, after opening the message, it is found that the message cannot be sent. When the Pusher console is opened, the information is displayed as a channel connection, but the message sending event is not executed. I open the local file (the local file and the deployment file use the same Pusher application), and the local file can be displayed on the deployed file. I haven't found the problem for a long time.

The structure of the entire project is as follows:

main.jsFile Content:

(function($){    var pusher  = new Pusher('18f9924cb7ee44a01ec0'),        channel = pusher.subscribe('imgondar');    Pusher.log = function( msg ) {        if( console && console.log ) {            console.log( msg );        }    };    channel.bind('send_message', function (data) {        Snarl.addNotification({            title: data.name,            text: data.msg,            timeout: 5000        });    });    $('form').submit(function(){        var say = $('#message').val();        if ( say ) {            $.post('post.php', $(this).serialize());            $('#message').val('').focus();        }        return false;    });})(jQuery);

post.phpFile Content:


  Htmlentities (getName (). ':'), 'msg '=> htmlentities (strip_tags ($ _ REQUEST ['message']),); $ pusher-> trigger ('imgondar ', 'Send _ message', $ data); function getName () {$ name_array = array (0 => "Dragon girl", 1 => "Yang Guo ", 2 => "Jin Yong", 3 => "Guo Jing", 4 => "Huang Rong", 5 => "Ouyang Feng", 6 => "Duan Yu ", 7 => "", 8 => "", 9 => "Mu Chen", 10 => "Java", 11 => "JavaScript ", 12 => "Python", 13 => "C ++", 14 => "HTML", 15 => "what a ghost ~~ ", 16 =>" cannot think of ^ ", 17 =>" a column ", 18 =>" just want to vomit ", 19 =>" Lu Ren jia ", 20 => "passers-by B", 21 => "Runner-up", 22 => "main character", 23 => "I am a female", 24 => "I am just a slave ", 25 => "Please call me Rong ma", 26 => "I will drop the 18 th palm of the Dragon", 27 => "", 28 => "speechless! -_-", 29 =>" Qiao Feng ", 30 =>" bad guy ",); $ index = rand (0, count ($ name_array)-1 ); return $ name_array [$ index];}

Visit the local http: // 127.0.0.1/imgondarv8_test/and click send. The following results are displayed in the browser:

Because I havemain.jsIn the code, let it output logs and open the browser console to see:

Open the Pusher console:

Now the problem arises. I deployed the code to the Linux server through svn and accessed it through the following Domain Name:
Http://testgondar.helloarron.com/

Clicking "send" does not work. The Pusher console and browser console information are as follows:


Although the connection is established, the message is not sent successfully.

However, I use the local http: // 127.0.0.1/imgondarv8_test/to send messages and receive messages (after all, the same Pusher application is used ), display the received information in the browser console:

After testing for half a day, it's in post. php.$pusher->trigger('imgondar', 'send_message', $data);Not executed in Linux.

ViewPusher.phpFiletriggerFunction:

public function trigger ( $channel, $event, $payload, $socket_id = null, $debug = false, $already_encoded = false ){    $ch = curl_init();    if ( $ch === false ){        die( 'Could not initialise cURL!' );    }    # Add channel to URL..    $s_url = $this->settings['url'] . '/channels/' . $channel . '/events';    # Build the request    $signature = "POST\n" . $s_url . "\n";    $payload_encoded = $already_encoded ? $payload : json_encode( $payload );    $query = "auth_key=" . $this->settings['auth_key'] . "&auth_timestamp=" . time() . "&auth_version=1.0&body_md5=" . md5( $payload_encoded ) . "&name=" . $event;    # Socket ID set?    if ( $socket_id !== null ){        $query .= "&socket_id=" . $socket_id;    }    # Create the signed signature...    $auth_signature = hash_hmac( 'sha256', $signature . $query, $this->settings['secret'], false );    $signed_query = $query . "&auth_signature=" . $auth_signature;    $full_url = $this->settings['server'] . ':' . $this->settings['port'] . $s_url . '?' . $signed_query;    # Set cURL opts and execute request    curl_setopt( $ch, CURLOPT_URL, $full_url );    curl_setopt( $ch, CURLOPT_HTTPHEADER, array ( "Content-Type: application/json" ) );    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );    curl_setopt( $ch, CURLOPT_POST, 1 );    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload_encoded );    curl_setopt( $ch, CURLOPT_TIMEOUT, $this->settings['timeout'] );    $response = curl_exec( $ch );    curl_close( $ch );    if ( $response == "202 ACCEPTED\n" && $debug == false ){        return true;    } elseif ( $debug == true || $this->settings['debug'] == true ) {        return $response;    } else {        return false;    }}

I think it may be that the php environment in linux is not enabled.curlModule, so I wrote a simple example of capturing the Baidu homepage and foundcurlYes. I can't find any other reason, and ask the experts to offer support. Thank you ^

The great God helped me solve the problem.

Check whether your php code has the execution permission!

In fact, when you open the Puser. php debugging mode, you will find that the returned status is 0.
Add the trigger method curl in Pusher. php

curl_setopt($ch,    CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,    CURLOPT_SSL_VERIFYHOST,false);

In this way, you can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.