|
Posted by shimmyshack on 03/21/07 21:46
On Mar 21, 8:28 pm, "Thorak" <diving...@gmail.com> wrote:
> On Mar 21, 10:07 am, "shimmyshack" <matt.fa...@gmail.com> wrote:
>
>
>
> > On 20 Mar, 21:00, "Thorak" <diving...@gmail.com> wrote:
>
> > > Im having a wierd problem with one of my php scripts opening a socket
> > > connection with session variables. My page is continualy returning
>
> > > Fatal error: Maximum execution time of 30 seconds exceeded in "bla bla
> > > bla" line 43
> > > line 43 is: $html .= fgets($fp, 4096);
>
> > > The thing is this code below works for me if i remove the line:
>
> > > $Headers .= "Cookie: ".$Cookie."\r\n";
>
> > > problem is then i don't have my session data filling in the form
> > > fields. As soon as I add this line so that the form fields can get the
> > > information needed then i get this Maximum execution error.
>
> > > I know im getting a result for: $Cookie = $_SERVER["HTTP_COOKIE"]
> > > cause of the echo that is returned and does match the echo of the
> > > session on all my other scripts.
>
> > > I have tried using things like: stream_set_timeout($fp, 60); to
> > > control this - but they dont seem to do anything. And changing the:
> > > $fp = fsockopen($URL, 80, $errno, $errstr, 30); to $fp =
> > > fsockopen($URL, 80, $errno, $errstr, 120);
>
> > > /*
> > > //==================================
> > > //==============================
> > > */
> > > session_start();
>
> > > $URL = "vinyl-design"; // localhost network connection
> > > $Cookie = $_SERVER["HTTP_COOKIE"]; // gives
> > > "PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1"
>
> > > $Page = 'interface2/order_details.php';
>
> > > $fp = fsockopen($URL, 80, $errno, $errstr, 30);
>
> > > // check if the website is found
> > > if(!$fp) {
> > > echo 'Failed opening socket connection!<br>'.$errstr.'('.
> > > $errno.')';
>
> > > }
>
> > > else {
> > > // write to the http server
> > > $Headers = "GET /".$Page." HTTP/1.1\r\n";
> > > $Headers .= "Host: ".$URL."\r\n";
> > > $Headers .= "Content-Type: text/html\r\n";
> > > $Headers .= "Cookie: ".$Cookie."\r\n";
> > > $Headers .= "Connection: Close\r\n\r\n";
> > > fwrite($fp, $Headers);
>
> > > // read the website
> > > while(!feof($fp)) {
> > > stream_set_timeout($fp, 60);
>
> > > // store the html into a variable
> > > $html .= fgets($fp, 4096);
>
> > > $info = stream_get_meta_data($fp); // get any error
> > > information
> > > while reading the data
>
> > > if ($info['timed_out']) {
> > > echo 'Connection timed out while trying to
> > > read data!';
> > > }
> > > }
> > > fclose($fp);
>
> > > }
>
> > > echo $html;
>
> > > /*
> > > //==============================
> > > //==================================
> > > */
>
> > Use a proper fully qualified domain name not some vinyl-server host.
> > change the hosts entry and use the REAL host you are going to use.
>
> > Try sending a list of proper headers.
> > Why are you sending
>
> > $Headers .= "Content-Type: text/html\r\n";
> > and
> > $Headers .= "Connection: Close\r\n\r\n";
> > typically thats what the server sends your user agent,
>
> > and also do you know what requirements the servrer application has in
> > terms of headers, use a proxy and browse round while logged in and
> > then copy the headers that are sent by your browser into your script.
>
> > They might look something like
>
> > $eol = "\r\n";
> > $Headers = "GET /".$Page." HTTP/1.1".$eol;
> > $Headers .= "Host: ".$URL.$eol;
> > $Headers .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT
> > 5.1; en-GB; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3".$eol;
> > $Headers .= "Accept: */*".$eol;
> > $Headers .= "Accept-Language: en-GB,en,fr-MC;q=0.9,fr;q=0.9,it-
> > IT;q=0.9,it;q=0.8,fr-FR;q=0.8,de-DE;q=0.8,de;q=0.7,en-US;q=0.7,pl-
> > PL;q=0.6,pl;q=0.6,zh-SG;q=0.6,zh;q=0.5,pt-PT;q=0.5,pt;q=0.5,hu-
> > HU;q=0.4,hu;q=0.4,sv-FI;q=0.4,sv;q=0.3,es-ES;q=0.3,es;q=0.3,nl-
> > NL;q=0.2,nl;q=0.2,nl-BE;q=0.1,it-CH;q=0.1,en-ZA;q=0.1,en-us;q=0.0".
> > $eol;
> > $Headers .= "Accept-Encoding: gzip,deflate".$eol;
> > $Headers .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7".$eol;
> > $Headers .= "Keep-Alive: 300".$eol;
> > $Headers .= "Proxy-Connection: keep-alive".$eol;
> > $Headers .= "Referer: http://".$URL."/".$Page.".$eol;
> > $Headers .= "Cookie: PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1".$eol.
> > $eol;
>
> > also be careful when posting your session ID, if your IP can be
> > guessed, people can easily make a connection to your application if
> > you allow public connections and use it as you, with annoying results.
>
> I cant change "vinyl-host" as this is an intranet site running on a
> network - there is no WWW to be had.
>
> This is what firefox is saying my header information is:
>
> <!--
> //=============================================
> // Headers returned from Firefox
>
> http://vinyl-design/interface2/order_details.php?OrderID=21425&CSR=Ry...
>
> GET /interface2/order_details.php?
> OrderID=21425&CSR=Ryan&CustID=&Page=1&OldOrder= HTTP/1.1
> Host: vinyl-design
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> 1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
> Accept: text/xml,application/xml,application/xhtml+xml,text/
> html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer:http://vinyl-design/interface2/order_detail_pages.php?OrderID=21425&C...
> Cookie: PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1
> Cache-Control: max-age=0
>
> HTTP/1.x 200 OK
> Date: Tue, 20 Mar 2007 22:26:50 GMT
> Server: Apache/1.3.31 (Win32)
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
> check=0
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Pragma: no-cache
> X-Powered-By: PHP/4.3.4
> Set-Cookie: PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1; path=/
> Keep-Alive: timeout=15, max=96
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: text/html
>
> //=============================================
> -->
this could be as simple as allowing the execution of the scripr to
continue over 30secs, which tends to be a default.
If you are using the machine to do a lot of work, or if the machine is
busy doing other things, then it might take longer than 30secs, I was
thrown off saying this because you said it worked if you removed the
session line - but I wonder now what that meant.
In general, the way I would approach logging in to a site would be to
use the cURL library, and store the crendentials (crendentials that
you know work) for that connection inside a cookie file for the
duration.
Also [from a pm] you are using this to output close of play print
outs.
Why not open word, create a super looking (but not TOO complicated)
doc
with a certain format.
Put stars where the content should go
Make a page break where you need it
Save as RTF (which is open format and text)
(no images)
then save the RTF as a string, and add in the vars from the database,
cycling through until the last page
This works quickly and can be sent for download and archiving, and/or
saved to the server, works with linux and windows.
is quick and small zipped up.
Its harder than it sounds though, but looks fantastic.
I woudl say this is a simple timeout issue rather than what I
suspected - some kind of session or header issue, as you clearly
control the server on which the code is running, and so should know
what it accepts in terms of headers.
Use the cURL library to make the connection and you should be fine.
You can use methods such as yours but why reinvent the wheel here,
especially as there are great examplse online in the manual. (and if
you ever go SSl, it can carry on working with only minor revision)
Navigation:
[Reply to this message]
|