# socket\_connect: permission denied

**URL:** <https://forum.kirupa.com/t/socket-connect-permission-denied/211832>\
**Category:** programming\
**Created:** [January 5, 2007, 4:12pm UTC](https://forum.kirupa.com/t/socket-connect-permission-denied/211832 "2007-01-05T16:12:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![govtcheeze](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@govtcheeze](https://forum.kirupa.com/u/govtcheeze)\
**Post date:** [January 5, 2007, 4:12pm UTC](https://forum.kirupa.com/t/socket-connect-permission-denied/211832/1 "2007-01-05T16:12:13Z")

</div>

I have a socket listener up and running (it’s from the flash/php tutorial on this site), which works fine with flash.

I have a test file:

```php
<?php
 
serverMessage("/SERVER test message");
 
function serverMessage($buf) {
 if(DEBUG_HASH) { logDebug("entering function <b>serverMessage</b> in sockTest.php: buf: [$buf]"); }
 
 $ip = "myIP"; // my real IP is in the file
 $port = myPort; // my real port is in the file
 
 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 if(DEBUG_HASH) { logDebug("socket: [$socket]"); }
 
 //socket_set_nonblock($socket);
 
 socket_connect($socket, $ip, $port);
 if(DEBUG_HASH) { logDebug("results: [" . socket_strerror(socket_last_error()) . "]"); }
 
 //socket_set_block($socket);
 
 $results = socket_write($socket, $buf);
 if(DEBUG_HASH) { logDebug("results: [" . socket_strerror(socket_last_error()) . "]"); }
 
 socket_shutdown($socket, 2);
 socket_close($socket);
 if(DEBUG_HASH) { logDebug("exiting function serverMessage"); }
}
?>

```

When I run it from shell, it parses the message and outputs to proper text to connected users.

When I call this function from within a php file that runs as a web page

```php
serverMessage("/SERVER test message"); 

```

I get the following error log (bolded red is the permission issue):

2007-01-04 23:26:26 – entering function **serverMessage** in sockTest.php: buf: [/SERVER test message]  
2007-01-04 23:26:26 – socket: [Resource id #42]  
[COLOR=red]**2007-01-04 23:26:26 – results: [Permission denied]**[/COLOR]  
2007-01-04 23:26:26 – results: [Broken pipe]  
2007-01-04 23:26:26 – exiting function serverMessage

Any ideas why I can’t connect from within the web based PHP script but I Can when connected to shell? Looks like some sort of perm issue, but many searches on google turned up no data I found to help resolve this issue.

Help ! 😃
