|
How to know whether the server has no data while reading the response of a request which is keep alive because the socket read function waits for the server to send data if we have made a request with keep alive option.
I am writing a socket program to fetch a webpage.
My request header has no connection close header so by default the connection is keep alive.
I open a connection, send the request header using socket_write and getting using a while loop to receive data
if it is a Connection Close request the everything works well.
if it is keep alive and after i have read the content the socket_read function is still waiting for data which causes the code to hand in there.
Here how do we know whether the server has completed sending the resource though it is keep alive...
i have a work around like checking the content-length response header to know how much data is received and accordingly i can stop reading
or
if response header has transfer-encoding as chunked then i can write more code to find the end of the response
yet without the above two workarounds how to check whether the socket_recv is still waiting for data?
Besides, i was thinking that since we are setting the read buffer length (like 1024 in this code) and the socket_recv is returning the no of bytes read and if the bytes read is less than 1024 then i can assume that the next read will not return anything and by this time i can quit the while loop.... BUT http server sends different length response so my logic will not work.
Here is my request header and the while loop in which i receive date from the server
//i have commented the connection close header so that by default it will be keep alive
$o = 'GET /search?hl=en&q='.$query.'&start='.$start.' HTTP/1.1'."\r\n";
$o.= 'Host: www.google.co.in'."\r\n";
$o.= 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0'."\r\n";
$o.= "\r\n";
do
{
$bytes = socket_recv($f, $tbuf, 1024, 0x40);
if($bytes === false)
die("\r\nUnable to read headers - ".socket_strerror(socket_last_error()));
echo "\r\n".$bytes;
if(!$bytes)break;
$buf.= $tbuf;
}while(1);
In the above code after i have received the complete html of a webpage the control is in the line where i am reading the response. Which i assume the code is still waiting for data from the server.
Suggestions, comments and advice's are welcome.
|
|
|
|
|
How can I create a chat application using PHP? I need the source code, not the downloadable app.
|
|
|
|
|
|
My 5.
Good link.
I had not seen it before posting mine.
|
|
|
|
|
Do you know most of the people don't even like to answer question like this.
I wish I could believe there is an after life.
|
|
|
|
|
Have you tried google?
This is the results page for the search "php chat source code": Google results[^]
|
|
|
|
|
I've created a facebook chat genre, by root, is very complicated but we can negotiate something!
|
|
|
|
|
|
hotscripts can be searched for many of its free scripts.
|
|
|
|
|
you may try http://www.dreamincode.net/forums/topic/44808-simple-text-chat-box/
|
|
|
|
|
How to highlight complete placeholder on MouseOver or when text is being inputted in the control within the placeholder? Example below.
_______________________________________________
|Name : | Joe Bloggs | |
| |________________ __| |
|____________________________ ______|
| |
DOB : |__________________|
| |
Address :|__________________|
|
|
|
|
|
Do you mean something like this[^]?
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Hello guys, I need to use Google image with my own program. When I save the WWW.image.google.com I am not able to see the camera Icon beside the search button. I need this camera icon to click on it automatically.
can anyone tell me what is the nature of this camera icon!? is it a button or just a clickable icon!?
Thanks and regards
|
|
|
|
|
To confirm and see what exactly it was, I did a ViewSource of the page.
I found it's a a-href link wrapped over a span that has image as a background. A-Href link triggers a JavaScript method.
|
|
|
|
|
This is great. Thanks. It made me clear,
|
|
|
|
|
|
|
Thanks, Actually I know only primary HTML and this looks strange for me. I will read those lines that you highlighted. Thanks in advance.
|
|
|
|
|
this is not html, this css
This Signature Panel is available for advertisement.
How to contact: go outside and yell my name.
p.s. If I don't reply, then your offer is not tempting
|
|
|
|
|
hosseinDolat wrote: what is the nature of this camera icon!?
It helps you to search based on an image instead of text. Just click on it and see what it does.
|
|
|
|
|
Thanks, I wanted to do the image searching in an automathic way so I just was not able to find the button when i saved the page. Using the advices from other friends in this webpage, I found that the camera is just an icon and behind it there is a href which addresses a java scrips code.
So thanks every one for help
regards
|
|
|
|
|
Hi all,
I've problem with send email using php. I used this code:
IsSMTP();
//GMAIL config
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myaccount@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
//End Gmail
$mail->From = "<myaccount@gmail.com>";
$mail->FromName = "I am";
$mail->Subject = "Test";
$mail->MsgHTML("the message");
//$mail->AddReplyTo("reply@email.com","reply name");//they answer here, optional
$mail->AddAddress("myfriend@gmail.com","Myfriend");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {//to see if we return a message or a value bolean
echo "Mailer Error: " . $mail->ErrorInfo;
} else echo "Message sent!";
?>
After I running the code and I get this error :
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
Why this code isn't running properly? What should I do?
Thank you,
Reinhart
|
|
|
|
|
Try replacing
"smtp.gmail.com"; with
"smtp.googlemail.com";
modified 1-Aug-19 21:02pm.
|
|
|
|
|
Hi richard,
Thank you for your previous answer.. I've tried your idea but it is still not working with error message:
"SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (118706120)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host."
Does any configuration should I do?
|
|
|
|
|
In the php.ini file, have you uncommented
extension=php_openssl.dll
This you can try
require("PHPMailer/class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'username@gmail.com';
$mailer->Password = 'yourpassword';
$mailer->From = 'from@gmail.com';
$mailer->FromName = 'namefrom';
$mailer->Body = "your message";
$mailer->Subject = "subjectname";
$mailer->AddAddress(joeblogs@fredsmith.com);
if(!$mailer->Send()) {
error_log("Mailer : error ".$mailer->ErrorInfo)." : $to";
echo "fail";
}
else {
echo "sent";
}
modified 1-Aug-19 21:02pm.
|
|
|
|