Jump to content

Recommended Posts

\

I have installed php 5.4.13 on Linux 2.6.34.

I have make simple client/server page using socket but it did not work on it.

It give permission denied error

Below is my php code

if (false == ($socket = socket_create(AF_INET, SOCK_STREAM, 0))) // create socket

{

$stringData= date("D M d, Y g:i A"). " socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br>";

echo $stringData;

}

else

{

$timeout = array('sec'=>5,'usec'=>500000);

socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout);

 

if(false==($result = socket_connect($socket, $host, $port)))

{

$stringData= date("D M d, Y g:i A"). " socket_connect() failed: reason: " . socket_strerror(socket_last_error()) . "<br>";

echo $stringData;

socket_close($socket);

}

else

{

$stringData= date("D M d, Y g:i A"). " Socket connected succefully <br>";

echo $stringData;

 

if(false==(socket_write($socket, $command, strlen($command))))

{

$stringData= date("D M d, Y g:i A"). " socket_write() failed: reason: " . socket_strerror(socket_last_error()) . "<br>";

echo $stringData;

socket_close($socket);

}

else

{

if(false===($cmd = socket_read ($socket, 65536)))

{

//10060 for windows and 11 for linux

 

if(10060!=socket_last_error() && 11!=socket_last_error())

{

$stringData= date("D M d, Y g:i A"). " socket_read() failed: reason: " . socket_strerror(socket_last_error()) . "<br>";

echo $stringData;

socket_close($socket);

 

}

switch(socket_select($r = array($socket), $w = array($socket), $f = array($socket), 5))

{

case 2:

$refused=1;

break;

}

if($refused==1)

{

$stringData= date("D M d, Y g:i A"). " socket_read() failed: reason: Connection Refused <br>";

$ourFileHandle = fopen(SOCKET_LOG, 'a');

echo $stringData;

socket_close($socket);

 

}

}

else

{

echo "<pre>".html_entity_decode(print_r($cmd,true))."</pre>";

}

}

}

}

 

 

 

Above code work fine on command prompt but it gives error Permission denied when page open from any browser.

Command of run php from terminal : /usr/local/rootfs/php5/bin/php /www/socket_client.php

 

I have found something new related to user permission which can not allow to create socket from web interface. I can run php process from command promt with root user and can able to create socket successfully without any failure cases.

 

can any one have idea how to solve above issue without SElinux support because i don't have SElinux support in my system?

 

Please let me know as soon as possible because its a cusial issue for me to solve and also i have tried with all its possble test-cases regarding permission of php.ini,httpd.conf and whole apache folder to root user permission with 777 but still i can not create soclet while from php file wihle running php file on web interface.

 

I can only create that socket only on command prompt with root user login access. I can not create socket with not-root user.

 

I have also tried to changed root and group in httpd.conf file but still it fails to start httpd process with root user.

 

so is there anyone have idea about what to do with this issue?

 

 

First, a couple of things:

1) If you post code, wrap it in


tags (the <> button on the editor toolbar). This makes it much easier for people to read

2) You posted in the incorrect forum. The forum you posted in is for questions/comments about the PHP Freaks website, not for code help. I've moved the thread.

 

 

As for your issue, which call specifically is failing? What is the exact error you are getting? Do some debugging to narrow down the problem area to within just a few lines.

 

Are you positive that you do not have SELinux enabled? Your symptoms sound like a SELinux problem. The ability for apache to create sockets is generally revoked in the few SELinux environments I've encountered.

I haven't support of SE linux in my board. That's why i can not able to solve this problem uszing SElinux support.

 

It gives permission denied error while running above problem through web browser which indicates that we can not create socket due to user permission problem for httpd.

 

I have already tried all the way to solve this issue but still failed to solve this issue.

I have debug using strace and found following log while running php based socket file on command prompt.

 

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = -1 EACCES (Permission denied)

 

Do you have any idea how to solve this issue?
 

The only time I've seen a permission denied error when creating a socket is when SELinux is enabled, so if you are certain it is not enabled, then I don't know of any other cause.

 

Try running echo 0 >/selinux/enforce just to make sure, and try the script again.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.