PHP Fatal error: Failure in wincache (windows azure) - php

I have codeigniter framework in my project. My website is running on windows azure platform. Sometimes it's giving me this error:
PHP Fatal error: Failure in Wincache[6484] free_memory: Block 0x41d56d8 not in use
in D:\home\site\wwwroot\system\libraries\Log.php on line 44
I tried to change php.ini file by changing value of memory:
ini_set('memory_limit','2048M');
But, then after I checked memory_get_peak_usage(); then I found that application is not even using more than 1MB. I don't know what's going on here. I am getting blank page and website gets down when this happens.
Please, ask me if you need more information or code.
Log.php:
public function __construct()
{
$config =& get_config();
$this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) // This is line 44.
{
$this->_enabled = FALSE;
}
if (is_numeric($config['log_threshold']))
{
$this->_threshold = $config['log_threshold'];
}
if ($config['log_date_format'] != '')
{
$this->_date_fmt = $config['log_date_format'];
}
}
log.php file is default codeigniter file.
FINAL SOLUTION:
I have updated my php.ini file with this:
wincache.fcenabled=0
wincache.ocenabled=0
wincache.ucenabled=0
wincache.reroute_enabled = 0
wincache.srwlocks = 0

It's an issue with IIS or WinCache on Windows Server. You can follow official thread on a iis forum.
Just to be sure, check following options in your php.ini:
wincache.reroute_enabled = 0
wincache.srwlocks = 0
Also update wincache to a latest version.

The specific WinCache error message has been removed as of WinCache 1.3.7.5, which was pushed out in a recent Azure Web Services update.
As for the meaning of the error message: While attempting to free a block of memory in a cross-process shared memory segment, WinCache detected that the block had already been freed. The message indicates that WinCache detected the problem, and avoided corrupting memory. The message should really be a Warning level message. Further, the executing request should run to completion, and a response should be returned to the customer.
Prior to WinCache 1.3.7.4, WinCache did not detect this scenario, and would wind up corrupting memory, which would eventually lead to an AV. So, the error message actually indicates that WinCache just saved you from crashing, and you're welcome!

Related

Facing issue while performing file reading operations in php

I am new to php . Currently as part of Migration activity we copied the existing php application to a new infrastructure where we are facing a strange issue.
Problem Statement:
From the php application,not able to read any file and it is not throwing any errors also. I used the following libraries and got the same behavior:
file_get_contents (This is the existing mechanism and I should use this one in the new infrastructure also)
Below two, checked to triage the issue:
readfile
fopen (tried with fopen just to see whether able to open like fopen($file, "r") or die( ),but this is also going to die condition
Issue Triaging
Made the below sample.php and make it available in my current server configuration. This is available by accessing through url (for e.g. https://myapplicationdomain/myapplication/sample.php). This php component is reading an input.txt which is in the same directory (actually this is the simulation of our problem)
<?php
ini_set('display_errors', 1); // show errors
error_reporting(-1);
//set your own error handler before the call
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
{
throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
}, E_WARNING);
echo "fopen url is";
var_dump(ini_get('allow_url_fopen'));
try{
$file ='input.txt';
if(is_readable($file)) {
echo "$file is readable \n"
} else {
echo "$file is not readable \n";
}
if(file_exists($file))
{
$homepage = file_get_contents($file);
var_dump($homepage);
echo "content is $homepage \n";
}else{
echo "file is not present \n";
}
}catch (Exception $e) {echo 'Error Caught $e';}
?>
Apache server is running using apache user and this user is having permission in the files and parent directories,
Following are the observations we got during triaging this:
When accessing through url for e.g. https://myapplicationdomain/myapplication/sample.php (i.e. through apache server).
a. functions is_readable & file_exists are returning true.
b. file_get_contents is returning blank and when I did var_dump, it is returning 'Null'
c. Confirmed the value of allow_url_fopen and it is returning 1 which is true
d. No errors are getting logged in this case.
e. Changed the permission of the 'input.txt' to see the permission behaviour. In that case,proper error got displayed in is_readable it self.So through this way ruled out the possibility of permission issue and also confirmed the error handler implementation is working fine.
f. Changed the location of input.txt to outside folders . ie. home/apache_user/ or root directory. Still file read operations are failing.
Able to run the same php code independently. i.e php sample.php .In this case,it is working as expected and all file reading operations are working fine.
3.Checked all the below php.ini configurations (removed all the values in disabled functions for testing)
a. open_basedir => no value
b. disabled_functions => no value
c. allow_url_fopen => true
Checked all the posts ,but not getting any idea how to proceed further. Following are version we are using: PHP 7.3.5 , CodeIgnitor framework and also configured php-fpm.
As per my understanding php library which apache was referring had some issues. Since it is a migration project and it is working fine in the current environment,copied the existing php folder (which was inside apache) and fpm binaries and configurations from the working environment to the new environment.Still not got any idea on exact root cause (as only read scenario was failing),but this got worked

Symfony 4 : Default value for parameters with a class type can only be

I am currently working on an application in symfony 4. I encounter a problem for deploy in prod. when I get to the navigator I get this error :
Fatal error: Default value for parameters with a class type can only be NULL in /var/www/html/project/vendor/symfony/config/ResourceCheckerConfigCache.php on line 40.
public function __construct(string $file, iterable $resourceCheckers = array())
{
$this->file = $file;
$this->resourceCheckers = $resourceCheckers;
}
I specify that the site works perfectly with the dev server (php bin /console server:start)
The problem must come from the environment. in the .env file, when I set APP_ENV=dev , in the browser there is only a blank page with a status 500 (no message in the logs)
I can not find any documentation on the internet and I am starting to lack ideas. If someone has a solution I am interested.
Thank you.
Solution by OP.
The problem was that the PHP version was PHP 7.0 and not 7.1. Though in my shell the php -v command was fine with 7.1, I noticed the wrong version used by phpinfo ();

laravel 5 show blank page on server error (and no laravel log), running with hhvm and nginx

I followed Fideloper post about running laravel with hhvm, step by step. There are two projects hosted on my server, one is my blog which is based on wardrobe (laravel 4.1), and another project with laravel 5.
My blog has no issue with server errors and laravel log file; But the other project cannot create log files, and it won't show error page because of that.
I double checked storage folder permission. It is 777.
When I run php artisan serve (native php, not hhvm) and browse to it, the error page showed up, and log file was created. So something is wrong with hhvm I think.
How can I fix blank page, when running laravel 5 with hhvm, and an error occurred? How can I bring back the error page (or whoops page)
P.S. I have read related question like this and still have the problem.
P.S.S. If any information needed ask me and I will update the question.
I suffered the same problem when I installed Laravel Homestead with HHVM. If you enter some random junk like sdfkjl into your routes file you'll get a blank page (however, if add a semi-colon sdfkjl; you get error output). The errors are being logged at /var/log/hhvm/error.log but they don't go to the browser, instead you just get a blank page. It appears this is intentional behavior for HHVM. It also appears Laravel tries to handle these but doesn't catch some of the fatals sent by HHVM. Thanks to clues from this github issue I decided to make some slight changes to Laravel's Foundation\Bootstrap\HandleExceptions.php to see if I could get it to catch all of these fatals:
First, update your /etc/hhvm/php.ini and add these settings:
hhvm.server.implicit_flush = true
hhvm.error_handling.call_user_handler_on_fatals = true
Before modifying a package source, let's remove the vendor\compiled.php with this artisan command:
$ php artisan clear-compiled
And let's set the environment sessons to array:
in your .env
SESSION_DRIVER=array
(You may also need to clear all the random-looking session files in storage/framework/sessions)
Now any changes we make to the Laravel package source will immediately reflect. Let's update a few things in the HandleExceptions class:
in vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
// **** Add this to hold fatal error
protected static $fatalError = null;
...
public function handleError($level, $message, $file = '', $line = 0, $context = array())
{
// **** Add this, loads fatal error
if ($level & (1 << 24)) {
self::$fatalError = array(
'message' => $message,
'type' => $level,
'file' => $file,
'line' => $line
);
}
if (error_reporting() & $level)
{
throw new ErrorException($message, 0, $level, $file, $line);
}
}
...
// *** Update this function so it can handle the fatal
public function handleShutdown()
{
$error = error_get_last();
if(self::$fatalError){
$error = self::$fatalError;
}
if ( ! is_null($error) && $this->isFatal($error['type']))
{
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
...
protected function isFatal($type)
{
// *** Add type 16777217 that HVVM returns for fatal
return in_array($type, [16777217, E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]);
}
...
Now type the random junk (no semi-colon) in your routes folder and you'll see the fatal display. I have now reported this issue to Taylor on the Laravel github. If you are in Lumen, I've got a solution here that will work until Lumen gets fixed as well.
I also got the same issue. Give 755 permission to entire laravel project it's work for me
anyway you can check hhvm error log, run
$tail -n 50 -f /var/log/hhvm/error.log

PHP fatal error on creating Com Object

I have a php web application that needs to access a PI-Datasource using an application-library written for windows on dll form to fetch the data. Due to the non-polimorphism of PHP we are using a wrapper written in C#-Dotnet in order to use the polimorphism library.
PHP->Wrapper->Lib->PI-System
The problem: PHP crashes, without leaving a log, on the creation of the com object (almost always on every second request). My thought was that probably something in the existing php code could be wrong that causes this fatal-error and after a lot of debugging and trying I simplified the code to this:
$connection = new Com('Something.SomethingClass');
with the variable $connection not being used NEVER! and still every 2nd time I get php-crash (documented in windows error log with an 1000-Error and an 1001-Information)
>Faulting application name: php-cgi.exe, version: 5.4.11.0, time stamp: 0x511a30ec
>Faulting module name: KERNELBASE.dll, version: 6.1.7601.17932, time stamp: 0x503275ba
>Exception code: 0xc0000005
>Fault offset: 0x0000d3cf
>Faulting process id: 0x14d0
>Faulting application start time: 0x01ce89dd0ae23748
>Faulting application path: C:\Program Files\Zend\ZendServer\bin\php-cgi.exe
>Faulting module path: C:\Windows\system32\KERNELBASE.dll
So i tried to generate even more com objects..
$connArray = array();
for($i = 0; $i < 50 ; $i++){
Core_System_Log::getInstance()->logWithoutMessageId('Before: ' . $i ,Core_System_Log::DEBUG);
$connArray[i] = new Com('Something.SomethingClass');
Core_System_Log::getInstance()->logWithoutMessageId('After: ' . $i, Core_System_Log::DEBUG);
}
All 50 were generated with no problem, and again every 2nd time i tried i got a php fatal error.
I tried to used all 50 of them, and they all read values from the PI-System with no problem.
I tried to unset the variables and call also the gc, call the destructor from C#, check the constructor from C# (which just makes an object of the library and had no exception, the object was normally created and still php crashed) but the problem did not disappear.
So, is there any idea? am i doing something wrong (how can it be wrong when every 2nd time it is properly reading the values)?
Environments Tested:
OS:Windows Server 2008 R2 64Bit / Windows 7 Prof SP1 32/64Bit
PHP: 5.3.9/ 5.3.14 / 5.3.21 / 5.4.11
WS: Apache and IIS (few different versions)
UPDATE: The problem was finally in the C# code. There was a call to GC which did not allow the COM object to be closed/deleted correctly having as a result C# to hang (again with no exception) and "triggering" the php fatal error.
Thanks for the responses.
If returns crashed without logging into file it look that in code contains sign #.
Example:
#some_function()
This will call function, but if has any errors it will not showing to you, just skipping. Due to some errors PHP can be stopped.
But, can you try upgrade PHP to 5.5 on Windows server?
If you know in which of lines of code throws an error and want to skip, just put isset()
If isset($somevar) or isset(function()) returns true that means are not errors, but if you don't want to stop a function on errors put isset() on a line of code where errors occurred.
I'm not sure how looks class and function inside PHP->Wrapper->Lib->PI-System code so I can tell fully corrected answer.
UPDATE: The problem was finally in the C# code. There was a call to GC which did not allow the COM object to be closed/deleted correctly having as a result C# to hang. The object was somewhere kept in Ram and the second time the wrapper was called it just hanged/exited (again with no exception) which "triggered" the php fatal error.

Multiple requests conflict time to read or copy a file

Details:
PHP Version: 5.3.0
Apache 2.2.37
Windows XP SP3
I am creating a system backup error (php error and custom error) in TXT, not user data but the dynamically generated page.
If you have already generated the LOG other user does not need to generate as ever existed.
I simulated 10 concurrent connections/requests and sometimes this error occurs:
No such file
Code:
<?php
$p = 'errs/'.$arqErr;
$o = 'temp/'.$arqErr;
if(file_exists($o) && is_readable($o) && is_writable($o)){
if(!copy($o,$p)){
echo 'Error copy "',$p,'" to "',$o,'"';
}
if(file_exists($o) && is_readable($o) && is_writable($o)){
unlink($o);
}
}
?>
sometimes the error occurs:
Warning: Unable to open 'temp/6039dd66559c9431004109202d279557.php' for reading: No such file or directory
and sometimes the error occurs:
Warning: Unlink failed (No such file or directory)
Is it a bug of PHP_5.3.0?
Note: In Windows Seven with PHP5.3.4 this failure does not occur.
The problem seems to be having multiple concurrent users trying to access the same files, it doesn't seem to be a PHP related problem.
Try to think of a different logging scheme, maybe using the error_log() function you can have PHP manage concurrency access issues for you.
<?php
error_log('Log message', 3, "md5(address of the page).LOG.txt");
?>

Categories