472,989 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

array results > fputs > responses captured and stored

This is a strange one but I've been stuck on it for days. Any help
appreciated.
THE PLAN:
I've a database that I use a script to grab all the entries for a
particular field.
I then want to send each of these entries individually to another
server using fputs.
The server will send 1 response (a lin of text) back for each item
sent to it.
I'd like to capture these responses and store them in a table.

WHAT I HAVE:
I can send 1 item manually at a time and get a response back from the
remote server. The connections and sockets are all working. I can
print the list of entries I'm grabbing, ready to send to the server. I
can print the server response to the screen for a single manually sent
item.
So my problem is that I don't know how to send or loop the field
entries that I grab from my database 1 by 1 automatically and quickly,
and then capture the remote server responses - inserting them to a
table.

MY CODE SO FAR (notated where I've fudged things a little):
If anyone can help I would really appreciate it. Please reply if you
have the skills to solve this - it's been wasting my days :(
<?php

$fp = fsockopen ('remote-server-address.com', port, $errno, $errstr,
30);

if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{

// get list of items from local database

$host="localhost"; // Host name
$username="localusername";
$password="localpassword";
$db_name="localdatabasename";
$db_con = mysql_connect("$host", "$username", "$password")or die
("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT fieldname FROM tablename";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$items = "{$row['domain']} <br>";

// prints a list of the items
// i don't need the script to do this, but just checking the contents
of the variable

echo $items;
}
// send and receive to and from remote server
// I really want to get rid of the first line below and just send
$item results directly
// into the $itementervariable
// and have the fputs run quickly sending each of the items to the
remote server and
// capture the server responses
// then eventually store each of the server responses into another
table.
$itementer = "testmessage";

fputs($fp, "$itementer\r\n");

$remote-server-response = fgets($fp, 128);
// prints the server response
// i don't need the script to do this, but just checking the contents
of the variable
// at the moment I'm specifying $itementer = testmessage so only a
single
// response is printed from the line below
// eventually need the list of many responses to be entered into a
table on the db

echo $remote-server-response;

fclose($fp);
}
mysql_close($db_con);

?>

Nov 15 '08 #1
5 2749
ma**@londonstudent.co.uk wrote:
This is a strange one but I've been stuck on it for days. Any help
appreciated.
THE PLAN:
I've a database that I use a script to grab all the entries for a
particular field.
I then want to send each of these entries individually to another
server using fputs.
The server will send 1 response (a lin of text) back for each item
sent to it.
I'd like to capture these responses and store them in a table.

WHAT I HAVE:
I can send 1 item manually at a time and get a response back from the
remote server. The connections and sockets are all working. I can
print the list of entries I'm grabbing, ready to send to the server. I
can print the server response to the screen for a single manually sent
item.
So my problem is that I don't know how to send or loop the field
entries that I grab from my database 1 by 1 automatically and quickly,
and then capture the remote server responses - inserting them to a
table.

MY CODE SO FAR (notated where I've fudged things a little):
If anyone can help I would really appreciate it. Please reply if you
have the skills to solve this - it's been wasting my days :(
<?php

$fp = fsockopen ('remote-server-address.com', port, $errno, $errstr,
30);

if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{

// get list of items from local database

$host="localhost"; // Host name
$username="localusername";
$password="localpassword";
$db_name="localdatabasename";
$db_con = mysql_connect("$host", "$username", "$password")or die
("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT fieldname FROM tablename";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$items = "{$row['domain']} <br>";

// prints a list of the items
// i don't need the script to do this, but just checking the contents
of the variable

echo $items;
}
// send and receive to and from remote server
// I really want to get rid of the first line below and just send
$item results directly
// into the $itementervariable
// and have the fputs run quickly sending each of the items to the
remote server and
// capture the server responses
// then eventually store each of the server responses into another
table.
$itementer = "testmessage";

fputs($fp, "$itementer\r\n");

$remote-server-response = fgets($fp, 128);
// prints the server response
// i don't need the script to do this, but just checking the contents
of the variable
// at the moment I'm specifying $itementer = testmessage so only a
single
// response is printed from the line below
// eventually need the list of many responses to be entered into a
table on the db

echo $remote-server-response;

fclose($fp);
}
mysql_close($db_con);

?>
You need to have your fputs/fgets within the while loop so you have
access to each row.

Just a word of caution - if you have a lot of data, your script may
timeout before you get it all processed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '08 #2
Thanks Jerry - that is what I thought but I've been getting so many
errors when I try and put it into the loop - I just can't place it
correctly.

Could you show me? Would help a lot

RE: timeout issues - do you know how I can stop that from happening -
at some days there may be 500,000 items being sent with responses
needed back and to be stored

Thx
Nov 15 '08 #3
Thanks Jerry - You helped me crack half of the problem - I figured out
the loop error I was making.
Nov 15 '08 #4
ma*****@gmail.com wrote:
Thanks Jerry - that is what I thought but I've been getting so many
errors when I try and put it into the loop - I just can't place it
correctly.

Could you show me? Would help a lot

RE: timeout issues - do you know how I can stop that from happening -
at some days there may be 500,000 items being sent with responses
needed back and to be stored

Thx
Nothing special about it - just something like:

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$items = "{$row['domain']} <br>";
// Format the data in $row as necessary here
// and put it in $itementer

fputs($fp, "$itementer\r\n");

$remote_server_response = fgets($fp, 128);

// parse the response here and place it in the database
}

If you have the proper authority, you can use ini_set to set
max_execution_time to 0 (disabled).

However, with 500K items, you're going to take a long time. You can run
into things like database or socket timeouts or all kinds of other
possibilities. And what do you do if you process 495,000 rows and get a
failure?

I think your error detection/recovery code is going to be even bigger
than your "work" code.

I know you didn't ask, but personally, I probably wouldn't do this in
PHP. I'd look at something like C or C++. Faster and lighter load on
the system.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '08 #5
Thanks for your help with this Jerry - I've made a lot of progress
with my project since a few hours ago - feels great when I'm getting
stuff done compared to fixing some code that should be easy!
Nov 15 '08 #6

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

Similar topics

5
by: G520 | last post by:
Hi I have been getting statistical rapports from a machine via a telnet server. Until now it has been done manually. However I want to automate the proccess, and scedule a PHP script to run...
0
by: t0642k8 | last post by:
Help , the script is executing nice , until it come to the section below. The data out of the Database is a full string with whitespaces in between each word. For example it the variable is "the...
5
by: Ian N | last post by:
Hi, I'm creating a site that posts orders to an email address when they're submitted, these orders need to be in the form of official invoices so i'm using HTML to format them. I already have...
6
by: Andreas Thiele | last post by:
Hi, I'm very new to php. In my current code I'd like to bind variables to the values of a simply (only indexed by numbers http://www.php-center.de/en-html-manual/language.types.array.html])...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
2
by: RadiationX | last post by:
How does this program work? // fig06_07.c -- COP2220 Example -- 040209 (sjd) // Student poll program #include <stdio.h> #include <stdlib.h> #define RESPONSE_SIZE 40 //...
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
3
by: jerrygarciuh | last post by:
Hi folks, As part of an app I am validating and repopulating user input from check boxes. $responses is posted checkbox input, $answers is the data used to create and recreate the checkboxes. ...
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.