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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:06:58+00:00 2026-06-07T09:06:58+00:00

I am trying to convert some code from perl to php. Perl code looks

  • 0

I am trying to convert some code from perl to php.

Perl code looks like below:

my $handle = Connect($port, $host);

and I am trying to use socket to do the same thing in php.
I have tried socket_create and socket_connect,
socket_create and socket_bind, and fsocketopen.

As a result, I’m stuck with error messages saying “Connection refused” or “permission denied”:

socket_connect() [function.socket-connect]: unable to connect [111]: Connection refused in

I am not sure if this is the problem I need to solve, or the problem of permission because the code in perl works fine (I did not write that code).

my php code looks like below:

$socket =  socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if(!$socket){
        die('Error: socket_create()');
}
if(!socket_connect($socket,$host,$port)) {
        die('Error: socket_connect()');
}

I’m not the one who manages the server, so I will need to ask someone else for the access if it is a permission issue. What should I ask for specifically?

Or should I use some other function to connect to the server? I am new to perl, so I am not sure if socket_connect is the equivalent function to use or not.

Thanks.

  • 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-07T09:07:00+00:00Added an answer on June 7, 2026 at 9:07 am

    If your perl code is able to establish the connection, no additional permissions should be needed to do the same in php. Connection refused means the remote host doesn’t let you in (you probably connect to wrong address/port). Permission denied is more surprising, a lot of people have this kind of problem while running httpd scripts with SELinux enabled. If you’re one of them, refer to the SELinux manpage:

    SELinux policy can be setup such that httpd scripts are not allowed to connect out to the network. This would prevent a hacker from breaking into you httpd server and attacking other machines. If you need scripts to be able to connect you can set the httpd_can_network_connect boolean on:

    setsebool -P httpd_can_network_connect 1

    I have a few concers to your examples though. Connect from your Perl snippet doesn’t seem to be the standard socket connect; I don’t know which module it belongs to, but are you sure there is no magic behind the call? As socket_connect takes address in dotted-quad notation (for IPv4), make sure you’re not passing a hostname (you would need to make a DNS lookup first). At the very end check if it’s really a TCP socket you need, not UDP.

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

Sidebar

Related Questions

I'm trying to convert some code from Richfaces 4 showcase to use CDI instead
I'm trying to convert some PHP code from Mysqli to PDO, and I need
I am trying to convert some code from using DOM (via jDOM) to use
There is some code that I'm trying to convert from IList to IEnumerable :
I am trying to convert some pages from my app to use cfc's, and
I'm trying to convert some code from Javascript to c. The function creates an
I'm trying to convert some code from Python to C++ in an effort to
I am trying to convert this code from C# to VB. Tried to use
I'm trying to write some code to convert data from a object type field
I am trying to convert some Verilog code that produces a slower clock from

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.