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");
?>
Related
I am using the Laravel filesystem calls - for example: Storage::disk('sftp')->put and it is working fine but I am wondering how I can view debug or error information if there ever were the need?
So for example if the file upload failed, how would I see that? When I first wrote the code it was not working and there was no Laravel exception screen and nothing in the laravel.log.
I'm in the same case.
I'm using Laravel Storage library with league/flysystem-sftp for sftp transfer. Here is the problematic line.
Storage::disk(self::REMOTE_DISK)->putFileAs($destFolder, $this->localFilePath, $destFilename);
Most of the time all is working fine. File is copied from local to remote without any problem.
But sometimes one problem occurs and I failed to understand what's occured during the transfer.
All I can do (at this time) is
$result = Storage::disk(self::REMOTE_DISK)->putFileAs($destFolder, $this->localFilePath, $destFilename);
if ($result === false) {
$exception = new FileUploadFailureException("file upload has failed");
}
Is there a better way to debug one sftp connection trouble ?
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
I´ve written a tool using PHPseclibs SFTP solution to uplaod various files to different target server. All targetserver are using wingFTP.
Under some conditions the upload fails without giving any debug message or error code.
I could figure out that the error (if it occures) allways occures in the following line of my code:
[...]
if(!$sftp->put($aResult[0]["targetpath"] . $sFilename, EXPORTFOLDER . "/" . $sFilename, NET_SFTP_LOCAL_FILE)){
[...]
Is there any way to see what is happening? There are no error messages or something... can I configure debug/error messages while using PHPseclib somewhere?
In about 95% of all cases the Upload is successfull and it does not only appear on one target server or for one file. Does someone have an idea where the problem could be located?
Thought I would drop a question, as this is giving me a proper headache
I have a PHP application which uploads files into SoftLayer Object Storage containers.
To communicate with the Object Storage API I am using the PHP bindings from
https://github.com/softlayer/softlayer-object-storage-php
and referenced them from my composer.json file
"softlayer/objectstorage": "dev-master",
Retrieving object container files and urls is working all fine.
But I keep having problems with uploading files though, specially depending on their size. It used to work couple of days ago but some reason stopped working recently
Here is the 'out-of-the-box' code I am using for uploading files:
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$objStorage = new ObjectStorage('', '', '', $options);
try {
$newFile = $objStorage->with('RemoteFilePath')
->setLocalFile($PathTolocalFile)
->create();
return $newFile->getUrl();
}
catch (Exception $e) {
return $e->getMessage();
}
For some reason, uploading a file that is under 1Mb works. But any file with a size bigger than this, the ->create() request eventually times out, no exception is thrown and I keep getting these error in my log:
xxx.xxx.xxx.xx - [05/06/16 03:47:02] Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages:
error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry (/var/www/vendor/softlayer/objectstorage/lib/ObjectStorage/Http/Adapter/Socket.php:132)
As those bindings are essentially a wrapper round curl, I then tested with CURL myself see if I could upload a file bigger than 1M to Softlayer Storage Container. It turns out it succeeded using CURL both on my dev machine and staging server!
curl -i -XPUT -H "X-Auth-Token: {{MyAuthToken}}" --data-binary "#BigFile.txt" https://lon02.objectstorage.softlayer.net/v1/{{MyAuthTokenKey}}/{{MyContainer}}/BigFile.txt
Have you ever come across this? I don't understand why it suddenly stopped working.
Has anyone any idea?
Thanks for reading
I was not able to reproduce your issue, I was able to upload files higher than 2 MB using your code.
Anyway, the issue that you have is related to SSL/OpenSSL broken, take a look the following links in order to get more information about it and how to solve it:
Bug #54439 SSL/OpenSSL
broken
fwrite(): SSL operation failed with code 1. OpenSSL Error
messages:\nerror:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write
retry IN
PHP
Why am I getting “error:1409F07F:SSL routines:SSL3_WRITE_PENDING:
bad write retry” error while attempting an
SSL_write?
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!