I want to have a push connection to my Client. It should be notificated if the file containts the word true. This works fine with the following script, but I always get a an Error after 50seconds. You see this error below.
How can I fix this error?
<?php
set_time_limit(3600);
$content ="";
while($content!="true"){
sleep(1);
$content = file_get_contents("test.txt");
}
echo "now";
?>
´ And here the Browser's result after 50seconds.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, sh@lorchs.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
My apache configuration:
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 3600
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 0
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
Search for max_execution_time
in your php.ini
Please not that file_get_contents()
returns a string of the whole file.
while-loop iterates as long as $content is not equal to only string "true". If you have a file that returns content "true" only then it will exit the loop, otherwise not.
I guess you're trying to do something like this:
<?php
$content ="";
while(!strstr($content,"true")) {
sleep(1);
$content = file_get_contents("test.txt");
}
echo "now";
?>
The code does not actually do anything beside creating an unnessecary loop for checking for a string inside a file.
Increase value of max_execution_time in php.ini & There is a setting max_input_time on Apache that defines how long they will wait for post data, regardless of the size. If this time runs out the connection is closed without even touching the php.
File get contents returns everything in 1 string. I think that what you want to do is loop through the lines and search if "true" is found in that line or not, find the location of true and then return everything before that?