I want to have persistent socket to send and receive data to a program written in C language on embedded linux on arm9 processor (this program has no problem in making and serving socket I tested it with other applications)
this is my code:
<?php
SESSION_START();
error_reporting(0);
@ini_set(‘display_errors’, 0);
if(!$_SESSION['randa']){
$_SESSION['randa'] = rand(1,99999);
}
echo $_SESSION['randa'] .'<br>';
$fp_a = pfsockopen("192.168.1.32",7777, $errno, $errstr, 30);
$outa = "D-1;".$_SESSION['randa'].';';
fwrite($fp_a, $outa);
$out_putt = fread($fp_a, 2048);
echo $out_putt ;
?>
<meta http-equiv="refresh" content="2;url=?">
as you see it reloads every 2 seconds. My goal is to prevent closing socket due to the PHP script exit and each session has its own persistent opened socket because of some reasons in my project,The above code works fine with apache and every session have their own persistent socket with no problem, the problem rises when I put this script in lighttpd with fastCGI enabled.
lighttpd opens persistent socket and everything goes fine for one session but if more that one session (web pages on different PCs) open, lighttpd share this persistent socket for all of them and does not open new socket for different sessions and all of them read each others data and sends their own data to one opened socket .
I used even this script too:
<?php
session_start();
if(!$_SESSION['views']){
$_SESSION['views'] = pfsockopen("192.168.1.32",7777, $errno, $errstr, 30);
$fp = $_SESSION['views'] ;
stream_set_blocking ( $fp , 0 ) ;
}else{
$fp = $_SESSION['views'] ;
}
$sread=fread( $_SESSION['views'], 1024);
if($sread==false and $sread!=''){
$_SESSION['views'] = pfsockopen("192.168.1.32",7777, $errno, $errstr, 30);
$fp = $_SESSION['views'] ;
stream_set_blocking ( $fp , 0 ) ;
}
if ($fp) {
$out = "D-1;";
fwrite($fp, $out);
$out_put = $sread.fread($fp, 2048);
echo $out_put ;
}
?>
<meta http-equiv="refresh" content="2;url=?">
to put persistent socket in session variable to prevent using same socket for different sessions but nothing changed and everything goes the same as first script did (one socket for all sessions ).
my config files are:
How can I prevent this problem? which configuration should I change for what to enable one socket for one session ??