473,626 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Functions in PHP

Hi all,

I suspect I'm having problems with socket functions within my PHP
application running on Red Hat 2.4.21-4.EL #1/PHP 4.3.2/Apache 2.0.46.

Below is a sample code listing:

=============== =============== =============== =============== ====

function sendRequest($st rRequest) {
$parser = NULL;
$logman = new LogManager();

$resource = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
$logman->append("Connec ting to OLS Server...");
$socket_conn = socket_connect( $resource, $serverIP, $serverPort );
if( $socket_conn ) {
$logman->append("Connec ted to {$serverIP}:{$s erverPort}.
Sending XML request...");
socket_write( $resource, $strRequest );
$logman->append("XML request sent. Waiting for XML
response...");
$document = "";
$data = socket_read( $resource, 1024 );

while ($data != "") {
$document .= $data;
$data = socket_read( $resource, 1024 );
}
$logman->append("XML response received.");

$parser = new OlsResponsePars er;
// parse the received document using our parser
$parser->parse($documen t);
}

if ($parser != NULL) {
return $parser->getOlsResponse ();
}

return $parser;
}

=============== =============== =============== =============== ====
The following listing is from the logs I have created...
=============== =============== =============== =============== ====

|+-------+---------------------+------------------------------------------------------------+
| LogId | LogDate | LogMessage |
+-------+---------------------+------------------------------------------------------------+
| 37 | 2006-05-03 15:39:28 | /new_userpage_pr ocess.php initialized.
Creating buffer... |
| 38 | 2006-05-03 15:39:28 | Connecting to OLS Server...
|
| 39 | 2006-05-03 15:39:28 | Connected to (server):(port) . Sending
XML request... |
| 40 | 2006-05-03 15:39:28 | XML request sent. Waiting for XML
response... |
| 41 | 2006-05-03 15:40:34 | XML response received.
|
| 42 | 2006-05-03 15:40:34 | Buffering complete. Redirecting to
thanks.php?acti ontype=2 |
+-------+---------------------+------------------------------------------------------------+

=============== =============== =============== =============== ====

As you can see, there is a lapse of more than one minutes between
LogId's 40 and 41, which is very slow on a production environment. The
script above acts as a client to another application server listening
on a remote port, running on Java. What the remote application reports
is that it receives the connection request, receives the request data,
and transmits the response data at the same second, while my
application receives the response one minute after the request was
sent!

Other implementations in the enterprise using different architectures
and technologies/languages do not experience the same issue as my app
does.

Please help. Comments, suggestions and thoughts through the group or
private mail are deeply appreciated.

Thanks!

May 8 '06 #1
2 1642
O.J. Tibi wrote:

<snip>
$resource = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
$logman->append("Connec ting to OLS Server...");
$socket_conn = socket_connect( $resource, $serverIP, $serverPort );
if( $socket_conn ) {
$logman->append("Connec ted to {$serverIP}:{$s erverPort}.
Sending XML request...");
socket_write( $resource, $strRequest );
$logman->append("XML request sent. Waiting for XML
response...");
$document = "";
$data = socket_read( $resource, 1024 ); <snip> | 40 | 2006-05-03 15:39:28 | XML request sent. Waiting for XML
response... |
| 41 | 2006-05-03 15:40:34 | XML response received.
|
| 42 | 2006-05-03 15:40:34 | Buffering complete. Redirecting to
thanks.php?acti ontype=2 |

+-------+---------------------+------------------------------------------------------------+
I suggest you point your script at an instance of netcat or similar and see
what's happening. I've not used the socket_ functions but perhaps its not
automatically flushing the buffer? I've not used the socket_ fns but didn't
have this problem using fsockopen().

Also, RTFM - "Note: socket_write() does not necessarily write all bytes
from the given buffer. It's valid that, depending on the network buffers
etc., only a certain amount of data, even one byte, is written though your
buffer is greater. You have to watch out so you don't unintentionally
forget to transmit the rest of your data."

It's generally bad practice not to check the return values of functions.
C.
May 11 '06 #2
Hi Colin,

I've also tried using the fsockopen() and fwrite()/fputs() combos in my
script, to no avail. The script still executes at the same rate as the
socket_x() functions that I have used above. AFAIK (correct me if I'm
wrong) fsockopen() and writing functions automatically flush the buffer
out, depending on the status of the I/O. If there are any explicit ways
of flushing the buffer, please do let me know.

I have a faint guess that the server is running a QoS (Quality of
Service) provider, the connection is being routed, or the connection is
being briged (although both the web server and the application server
reside in the same DMZ).

Thanks in advance. :)

May 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6364
by: Martin | last post by:
I am a PHP newbie (just got my "Hello World" page working this morning). I'm doing some R&D work to see if PHP is viable for a situation I have. To accomplish what I want to do, I have to have the PHP page communicate directly with another process. I want the PHP script to establish a socket connection to the other process, send a message and receive some data back which would then used for calculations and/or display on the resulting...
1
1911
by: Andrew Pasetti | last post by:
Using PHP Version 4.3.7/Apache/2.0.46 (Red Hat), I am not given access to php's socket functions. However, when I run the socket program by serving it as a web page, everything works as expected. Perhaps someone can suggest what to change or add from the command line call below to enable the socket functions. Your feedback will be greatly appreciated. Thanks,
4
11750
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
11
6846
by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the process). I want to be able to pass some of these new sockets to a spawned process. Is it possible, and if so how? Any help is much appreciated!! Mike
5
3679
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose but have been unsuccessful in finding the answers so far. Either because my understanding of sockets isn't where it needs to be or my questions are too basic. My programming environment is Windows XP, Visual Studio .NET 2003 and C#. So here it...
1
3387
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows XP. About the architecture: I have a socket server dll that contains a class that handles connections for a given local ipaddress and port. This class(server) can be started or stopped by calls to the appropriate functions. The server class has...
2
4146
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send I get the last chunk of data and am not able to retrieve it anymore cause the socket will be dead. Loop: { socket.Receive <----------- data arrives
6
2012
by: Luis P. Mendes | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I've developed a program that uses a socket to receive information 24h a ~ day. The problem is that the socket seems to freeze. By that I mean the program stops getting information but doesn't raise any error.
1
2722
by: Ismail Demiralp | last post by:
Hi, I want to open a permanent socket connection to a service witch is running on the same computer. After I logged in on my php page, I start a session. After this a socket connection should be opened to a service I get data from. Now my problem is I want open only once a socket connection to the service and after this I want use on all php pages this connection. How can I transmit (or use) this one connection on all pages ?
11
8592
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
0
8268
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.