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 7590425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:23:52+00:00 2026-05-30T20:23:52+00:00

What is the purpose of getSocket(type,persistence_id,callback) in zeromq? Will it create a new socket

  • 0

What is the purpose of getSocket(type,persistence_id,callback) in zeromq?

Will it create a new socket if one doesn’t exist with the same persistence_id in the context?

This is my client

function newSocket(ZMQSocket $soc, $pid)    {
    echo $pid;
}

$context = new ZMQContext();

$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'mysocket', 'newSocket');

$socket->setSockOpt(ZMQ::SOCKOPT_HWM,5);

$socket->connect("tcp://172.16.136.59:5555");
for($i=0;$i<10;$i++)
{
    var_dump($socket->send("hai",ZMQ::MODE_NOBLOCK));
    sleep(2);
}

How many ever times I run this client simultaneously[nth client after n-1th client started], the callback is getting executed.
Is this the desired behavior?
What are all the situations, where the socket structure will be reused?

  • 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-05-30T20:23:53+00:00Added an answer on May 30, 2026 at 8:23 pm

    What persistance does is signal the memory allocator to use the persistent memory allocation functions, which will alloc the context (and if you ask, any sockets) in a way that wont go away at the end of the request, but will last the lifetime of a PHP process. It sort of works the same way as some of the connection pooling libs, if that makes sense. The callback will be used on the first time the socket is created. Persistance needs to be set in the context, for example:

    <?php
    
    function newSocket(ZMQSocket $soc, $pid)    {
        echo "Creating New Socket \n", $pid, "\n";
    }
    
    echo "=========Creating without persistence ==========\n";
    
    $context = new ZMQContext(1, false);
    
    $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'mysocket', 'newSocket');
    
    $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'mysocket', 'newSocket');
    
    echo "========Creating with persistence ==========\n";
    
    $context = new ZMQContext(1, true);
    
    $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'mysocket', 'newSocket');
    
    $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'mysocket', 'newSocket');
    

    Will give you

    # php -dextension=zmq.so test.php 
    =========Creating without persistence ==========
    Creating New Socket 
    mysocket
    Creating New Socket 
    mysocket
    ========Creating with persistence ==========
    Creating New Socket 
    mysocket
    

    In the first instance, with false to persistance, the socket is recreated each time, and the callback fired. In the second, with persistance on, the socket is just returned, and the callback not triggered.

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

Sidebar

Related Questions

Purpose: I plan to Create a XML file with XmlTextWriter and Modify/Update some Existing
Purpose: Create a program that takes two separate files, opens and reads them, assigns
Purpose of the code : Create two Buttons(button1 and button2). When User clicks button1,
The purpose of this exercise is to create a population distribution of nutrient intake
My purpose is to process one image from image library, and save this image
Purpose & What I've Got So Far I am attempting to create a view
The purpose is to have a checkbox, that if clicked, will send via post
Purpose of the script : 1.This script will delete Files older than 4 months.
For testing purpose, I need to create logs in a CSV file in my
The purpose of using a Javascript proxy for the Web Service using a service

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.