PHP Softlayer Object Storage Upload SSL error - php

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?

Related

Why am I getting error no 21 when I generate a pdf using mpdf library in PHP, in live server?

I am using mPDF library to generate a pdf from my php server script. I have used composer to install the library into my live server file system.
I was being able to generate the pdf file successfully for quite a couple of months, until today morning. Everytime I try to generate the pdf it shows this error in the console:
Notice: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in /home/user/domains/report_generation/backend_pdfgen/vendor/mpdf/mpdf/src/File/LocalContentLoader.php on line 10
According to the console, I went to line 10 in LocalContentLoader.php. This is the code:
<?php
namespace Mpdf\File;
class LocalContentLoader implements \Mpdf\File\LocalContentLoaderInterface
{
public function load($path)
{
return file_get_contents($path);
}
}
This is my pdf generation script (pdfgen.php):
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf(['setAutoTopMargin' => 'stretch']);
$mpdf->SetTitle("report.pdf");
$mpdf->SetAuthor("Anonymous");
$mpdf->WriteHTML('<div style="text-align:center";>Some data here</div>');
$mpdf->Output("reports/report.pdf");
?>
My file hierarchy:
I am not being able to understand what's wrong with it. I surfed on the internet and found a post where it was mentioned that I have to increase the upload_max_filesize, it's already increased to 1 GB, but still the error message shows. Where am I going wrong. Please guide me.
Surprisingly, the error doesn't show when I run the script in my localhost server.
This is very likeley because of insufficient disk space.
Try another location or verify you have enough space. Check where report.pdf is intended to be safed.

How to view debug information or error information when using Laravel (7) filesystem calls?

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 ?

PHPseclib crashes while trying to upload via SFTP

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?

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");
?>

SoapClient: faultcode WSDL

When I try to use SoapClient:
try {
$client = new SoapClient('http://someurl/somefile.wsdl');
} catch (SoapFault $e) {
var_dump($e);
}
I have catch error with:
["faultstring"] => "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://someurl/somefile.wsdl' : failed to load external entity "http://someurl/somefile.wsdl"
["faultcode"] => "WSDL"
I can manually download http://someurl/somefile.wsdl and can file_get_contents for this file. I try to use it before on different computer and it worked. Possible problem with php or apache settings..
ArchLinux with last updates for php and apache. I tried to enable all php extensions.
Were you able to get wsdl using file_get_contents() in browser?
I had similar issue recently in Archlinux with same faultstring, no matter what wsdl file was used. The same code was working without any problem on other Archlinux machine and Windows XP box.
After some research, it came out that problem arose only when I tried to access the page in browser - script accessed from command line worked as expected. Then I changed the script to download the wsdl file directly, using aforementioned file_get_contents() - it gave me a warning "php_network_getaddresses: getaddrinfo failed: Name or service not known".
Few tutorials (on SO, or this one: http://albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/ ) later I haven't fought off the problem yet. But then I discovered what introduced the issues: I had been running NetworkManager since the installation of Arch (to better handle wireless), and few weeks later I've added mysqld and httpd as last to DAEMONS section in rc.conf - it seems this broke DNS resolution for apache.
Having two solutions (go back to starting servers manually or try other network manager) I've switched to wicd and haven't run into the issue again.

Categories