Speeding up a PHP program?

JonTheBaller

Golden Member
Dec 2, 2002
1,916
0
0
I wrote a program that I would like to speed up in two ways:

1. It reads data from a file, one line at a time, and based on what it reads it accesses a unique page at a certain site. This takes a long time, because there are 150 items of data in the file, so 150 connections have to be made. Is there anyway to speed this process up, possibly by making the connection more persistent?

2. Based on the data extracted from the web page it connects to, the program writes data in the format of an HTML table. However, the table is only displayed when the </TABLE> is written - after all the data is read. That means I can't see my results for a few minutes. A workaround for this is making each line its own table, instead of row of a larger table. However the columns end up unaligned.

Any solutions? Thanks.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
1. 99.999% of the time is spent waiting for the 150 server responses. I don't think an HTML 1.1 "keep-alive" would make any real difference for this. This is where a multithreaded (Win32) or perhaps multiprocess (unix/linux) application would make perfect sense. Divide up the work with 4-5 threads and the elapsed time should be cut to 1/4 - 1/5. After around 10 diminishing returns set in fast and/or your TCP/IP stack might not allow more connections anyway.

You might be better off doing this as a c/c++ app called from PHP unless there is threading / forking capability in PHP.

2. Multiple tables: did you try setting column widths to fix alignment problems?
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
Don't know about threading, and not sure if this is an issue or not but...

If you find that the connection time is not your problem, and that instead just your code is slow, check out Zend's PHP Accelerator.

You might also try running multiple instances of the same script, run the the script four times at once in 4 different browser windows, that way each script is making a connection. Not sure if that'll help or if thats the best solution though...

Internet Explorer will usually display data BEFORE the end </table> tag is written, Netscape and Opera generally do not. What browser are you using? Also, the colums really shouldn't end up unaligned if you set width="" attributes for them, are you doing that? Does the text overflow over those widths screwing up the widths of teh colums... otherwise theres really no reason that they colums should not line up.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Use a "flush" command to output everything you have so far, however the client is not obliged to draw everything until it feels like it.
This is one of the times where cascading style sheets would help, it would look like a table, but since you open and close an entire div section, most browsers will display the results immediately. When you use the flush command, that is.
 

m0ti

Senior member
Jul 6, 2001
975
0
0
I imagine there would be multi-threading in PHP. Multi-threading definitely is the way to go for anything that IO dependent.
 

JonTheBaller

Golden Member
Dec 2, 2002
1,916
0
0
I was able to fix the table not lining up problem. Btw I search for threads/concurrency in PHP and found nothing, any takers on this one?