Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:18:01+00:00 2026-06-01T11:18:01+00:00

How to send messages from php to node.js? I have a linux server running

  • 0

How to send messages from php to node.js? I have a linux server running php and node.js.

When a user completes a transaction (via php), I’d like send a message from php to node.js. Node will then update the client via a socket connection.

What’s a good way to send a small amount of data from php to node.js without defeating the performance of node.js?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:18:02+00:00Added an answer on June 1, 2026 at 11:18 am

    The suggestion seems to be to talk to node through the HTTP interface, just as any other client does. You can talk to node via HTTP using cURL in php

    See: http://groups.google.com/group/socket_io/browse_thread/thread/74a76896d2b72ccc/216933a076ac2595?pli=1

    In particular, see this post from Matt Pardee

    I faced a similar problem with wanting to keep users informed of a new
    note added on to a bug, and similar notifications that could really
    only be effectively sent from PHP to my Node server. What I did
    follows (apologies if this gets all garbled and unformatted in
    sending, if it does, I’d be happy to paste the code somewhere else):
    First, you’ll need to use cURL from PHP. I wrote a function for my
    class like this:

    function notifyNode($type, $project_id, $from_user, $data) {
        $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1');
    
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        curl_setopt($ch, CURLOPT_PORT, 8001);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    
        curl_setopt($ch, CURLOPT_POST, true);
    
        $pf = array('f' => $type, 'pid' => $project_id, 'user_from' => $from_user, 
                 'data' => array());
    
        foreach($data as $k => $v) {
            $pf['data'][$k] = $v;
        }
    
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($pf));
    
        curl_exec($ch);
        curl_close($ch);
    }
    

    You’ll notice that I send the cURL request on the same server since
    both PHP and NodeJS are running there, your mileage may vary. The port
    I set this code to connect to is 8001 (this is the port my Node server
    is running on, and the port the socket.io server connects to). This
    sends a HTTP POST request with the post field encoded. This is all
    pretty standard cURL stuff.

    In your Node app you probably have something like:

    var server = http.createServer(function(req, res) {});
    server.listen(8001);
    var io = io.listen(server, { transports: ['websocket', 'flashsocket', 'xhr-polling'] });
    
    ...
    

    well what we’ll do here is expand on the http.createServer part, to
    listen for connections coming from our local host (“127.0.0.1”). The
    createServer code then becomes:

    var server = http.createServer(function(req, res) {
        // Check for notices from PHP
        if(res.socket.remoteAddress == '127.0.0.1') {
            if(req.method == 'POST') {
                // The server is trying to send us an activity message
    
                var form = new formidable.IncomingForm();
                form.parse(req, function(err, fields, files) {
    
                    res.writeHead(200, [[ "Content-Type", "text/plain"]
                            , ["Content-Length", 0]
                            ]);
                    res.write('');
                    res.end();
    
                    //sys.puts(sys.inspect({fields: fields}, true, 4));
    
                    handleServerNotice(fields);                
                });
            }
        }
    });
    

    From there you can implement your handleServerNotice function..

    function handleServerNotice(data) {
            ...
    }
    

    etc etc. I haven’t tested this in a while, and in fact that code block
    was commented out on my node server, so I hope what I’ve pasted here
    works – in general this concept is proven and I think it’ll work for
    you. Anyway just wanted to be sure you knew it’s been a few months so
    I’m not sure exactly why I commented out. The code I wrote took a
    little research — like setting the ‘Expect:’ header in cURL — and I
    was pretty excited when it finally worked. Let me know if you need any
    additional help.

    Best,

    Matt Pardee

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a server to send and recieve XMPP messages from Android clients running
I want to send messages from php by using a GSM modem. I have
Is it possible to send messages from a PHP script to the console in
When i try to send a message from my client , the server is
What is the best way to send messages from PHP script to Java program
How can I have PHP 5.2 (running as apache mod_php) send a complete HTTP
I want to send JSON messages from a PHP script to a C# app
I am trying to send text messages to my phone from my server using
I tried to send messages from wordpress using gmail SMTP. Server is set to
I'm running PHP under Apache and I'd like to send a slow trickle of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.