The web page is on Symfony 2.5.2 with 5 selfcreated bundles and FOSUserbundle. It is rather large, but essentially resembles a blog with user comments.
It is on a shared OVH server.
It works in dev and prod, but when in prod : after one to three days I either receive an http error 500 or (more seldom) an empty page with the URL http://mypage.com/web//
The latter indicates that the route has not been found. Still the route MUST be there, as the problem appears "over night", i.e. intermittently.
When I have either one of these situations the following remedies "solve" the problem:
- clear the cache (I normally delete the whole directory app/cache/prod)
- pass the AppKernel from 'prod',false to 'prod',true (without clearing the cache
- passing into app_dev.php
I do not know if the intermittence would also occur for the case 2 (as I do not want to run the risk leaving the site open that way). For case 3: when going back to prod without having cleared the cache, the problem remains.
When I get an error 500, there is no entry in the log file.
Whenever I checked at the time I got the the empty page error (with the URL ending web// ), the log file has no entry; but there is an entry from hours before (from a visitor I suppose) indicating:
[2015-07-23 04:04:18] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /dir1/dir2/fr"" at /home/mysite/www/Symfony/app/cache/prod/classes.php line 1977 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: No route found for \"GET /dir1/dir2/fr\" at /home/mysite/www/Symfony/app/cache/prod/classes.php:1977, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException: at /home/mysite/www/Symfony/app/cache/prod/appProdUrlMatcher.php:545)"} []
I have tried
to add in web/app.php a
$response->setMaxAge(600);
which exhibits also intermittent errors (removed it again)to add an automatic cache removal in the homepage controller (to my defense: this was NOT intented as a solution, but for debugging only). It is removed again after intermittence remained still.
//---------- clears cache first user at midnight $dirDate=date('d',filemtime($this->container->getParameter('kernel.cache_dir'))); if (date('d') != $dirDate AND date('H')<6) { //--- from http://stackoverflow.com/questions/24115395/programmatically-clear-cache-on-symfony-2 $fs = new Filesystem(); $fs->remove($this->container->getParameter('kernel.cache_dir'));}
I tried to add
$kernel = new AppCache($kernel);
in web/app.php but couldn't get it to work at all (as it is outside my competency).
I cannot continue to manually clear the cache every day (or more often?) and the intermittent character of the problem does not allow for a typical trial-and-error-debugging excersize. I need help to understand the cause prior continuing taking "blind" actions.
I can certainly share more of the coding, but wouldn't know which portion to share with the community here. There is likely no "typical" bug, as the code always works for a while and the problem ONLY pops up after 1 to 3 days, intermittently.
Add-on after Francesco's comment:
There is no error in the log file in Symfony's app/log, but I found some in the (shared) server's log (logs.ovh.net). Still, these logs are only the consequence of the 500 error. There are two distinct messages (and many of each one):
[Sat Jul 25 23:29:07 2015] [error] [client 66.249.64.104] [host www.mywebsite.com] FastCGI: comm with server "/homez.437/myweb/www/Symfony/web/app.php" aborted: idle timeout (300 sec)
[Sat Jul 25 23:29:07 2015] [error] [client 66.249.64.104] [host www. mywebsite.com] FastCGI: incomplete headers (0 bytes) received from server "/homez.437/myweb/www/Symfony/web/app.php"
[Sat Jul 25 23:29:07 2015] [error] [client 66.249.64.104] [host www. mywebsite.com] FastCGI: An error happend on Fastcgi processing, fallback to CGI
[Sat Jul 25 23:29:10 2015] [error] [client 66.249.64.104] [host www. mywebsite.com] (103)Software caused connection abort: Failed to flush CGI output to client
[Sat Jul 25 22:35:58 2015] [error] [client 66.249.64.94] [host www. mywebsite.com] (104)Connection reset by peer: FastCGI: comm with server "/homez.437/myweb/www/Symfony/web/app.php" aborted: read failed
[Sat Jul 25 22:35:58 2015] [error] [client 66.249.64.94] [host www. mywebsite.com] FastCGI: incomplete headers (0 bytes) received from server "/homez.437/myweb/www/Symfony/web/app.php"
[Sat Jul 25 22:35:58 2015] [error] [client 66.249.64.94] [host www. mywebsite .com] FastCGI: An error happend on Fastcgi processing, fallback to CGI
The errors logged on the shared server occured whilst I could access the website with no problems. What does that mean?
UPDATE OF PROBLEM STATEMENT 3 MONTHS AFTER THE FIRST REV:
I finally managed to retrieve an error code by adding the following code to app.php (top of code before the first "use"):
ini_set('display_errors', 1);
error_reporting(-1);
The error then pops up in html under the site's uri:
- Notice: Undefined variable: matches in /xxx/app/cache/prod/appProdUrlMatcher.php on line 84
- Warning: array_replace(): Argument #1 is not an array in /xxx/app/cache/prod/appProdUrlMatcher.php on line 84
- Warning: Invalid argument supplied for foreach() in /xxx/app/cache/prod/classes.php on line 1414
- Notice: Undefined index: _route in /xxx/app/cache/prod/classes.php on line 1966
- Notice: Undefined variable: matches in /xxx/app/cache/prod/appProdUrlMatcher.php on line 84
- Warning: array_replace(): Argument #1 is not an array in /xxx/app/cache/prod/appProdUrlMatcher.php on line 84
- Warning: Invalid argument supplied for foreach() in /xxx/app/cache/prod/classes.php on line 1414
- Notice: Undefined index: _route in /xxx/vendor/symfony/symfony/src/Symfony/Component/Security/Http/HttpUtils.php on line 112
Line 82 to 85 of appProdUrlMatcher.php are
// mysite_publish_artWork
if (0 === strpos($pathinfo, '/gallery/publish') && preg_match('#^/gallery/publish/(?P<idOfArtWork>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'aliquam_publish_artWork')), array ( '_controller' => 'Aliquam\\ArtWorkBundle\\Controller\\ArtWorkController::publishArtWorkAction',));
}
NB: line 84 is the line starting with return $this->
When I simply add a CRLF (Notepad++) so that the code above looks like:
// mysite_publish_artWork
if (0 === strpos($pathinfo, '/gallery/publish') && preg_match('#^/gallery/publish/(?P<idOfArtWork>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'mysite_publish_artWork')),
array ( '_controller' => 'MySite\\ArtWorkBundle\\Controller\\ArtWorkController::publishArtWorkAction',));
}
then the error 500 disappears and the page loads.
This appProdUrlMatcher.php is not a class I created; it is part of the symfony created cache. Surely, I can delete it and it will then work for a while until the error pops up again.
The route is a route to a (secured, only admin access) controller. whilst all these intermittent issues happened I di d not call the route once. NB: when I call the route as administrator it does work. Here is the yml of the route:
mysite_publish_artWork:
pattern: /publish/{idOfArtWork}
defaults: { _controller: MysiteArtWorkBundle:ArtWork:publishArtWork }
requirements:
idOfArtWork: \d+
and the corresponding controller
public function publishArtWorkAction($idOfArtWork)
{
$em=$this->getDoctrine()->getManager();
$repository=$em->getRepository('AliquamArtWorkBundle:ArtWork');
$artWork=$repository->find($idOfArtWork);
$listOfArtWork=$repository->findAll();
if (isset($idOfArtWork))
{
if ($artWork->getPublicate()==true){$published=false;}else{$published=true;}
$csrfProvider = $this->container->get('form.csrf_provider');
$unique_fake = $csrfProvider->generateCsrfToken('unique_fake');
if ($this->getRequest()->query->get('csrf_unique_fake')==$unique_fake)
{
$artWork->setPublicate($published);
$em->persist($artWork);
$em->flush();
$translatedText = $this->get('translator')->trans('message.flash.modified');
$this->get('session')->getFlashBag()->set('infoGlobal',$translatedText);
}
foreach ($listOfArtWork as $l)
{
$l->setContent(substr($l->getContent(),0,25)."...");
}
}
return $this->redirect($this->generateUrl('mysite_manage_artwork'));
}
I can delete/clear the cache, but would it make really sense to rewrite a file in cache/prod/ ? I don't think that's a good idea. But I am short of any other.
And, something which happened today: I can access the site on my PC, but not on my cell phone (Windows Phone).