perl - "Connection refused" error on socket_connect in php -


i trying convert code perl php.

perl code looks below:

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

and trying use socket same thing in php. have tried socket_create , socket_connect, socket_create , socket_bind, , fsocketopen.

as result, i'm stuck error messages saying "connection refused" or "permission denied":

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

i not sure if problem need solve, or problem of permission because code in perl works fine (i did not write code).

my php code looks 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 1 manages server, need ask else access if permission issue. should ask specifically?

or should use other function connect server? new perl, not sure if socket_connect equivalent function use or not.

thanks.

if perl code able establish connection, no additional permissions should needed same in php. connection refused means remote host doesn't let in (you connect wrong address/port). permission denied more surprising, lot of people have kind of problem while running httpd scripts selinux enabled. if you're 1 of them, refer selinux manpage:

selinux policy can setup such httpd scripts not allowed connect out network. prevent hacker breaking httpd server , attacking other machines. if need scripts able connect can set httpd_can_network_connect boolean on:

setsebool -p httpd_can_network_connect 1

i have few concers examples though. connect perl snippet doesn't seem standard socket connect; don't know module belongs to, sure there no magic behind call? socket_connect takes address in dotted-quad notation (for ipv4), make sure you're not passing hostname (you need make dns lookup first). @ end check if it's tcp socket need, not udp.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -