Suddenly this line
$data_to_send = @file_get_contents($source);
giving me an error
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Allowed memory size of 536870912 bytes exhausted (tried to allocate 353912831 bytes)","file":"/home/forge/site/app/commands/ExportProductsDiff.php","line":157}}
I already upgrade my Linode VM to this plan already and still didn't seeing the error.
ExportProductsDiff.php
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ExportProductsDiff extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'products:exportdiff';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Export all products to Diff.';
/**
* The system export message.
*
* @var string
*/
protected $system_message = '[System Diff Export]';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// Export the products by calling the ExportProducts Command
$options = [
'--format' => "distributor",
'--encoding' => "standard csv",
'--categories' => "all categories",
'--conjugate' => 1,
'--export_notes' => $this->system_message
];
if($this->option('interval') == 'daily'){
$options['--date_range'] = date('Y-m-d');
$options['--include_disabled'] = 1;
}else if($this->option('interval') == 'daily active'){
$options['--date_range'] = date('Y-m-d H:i:s');
// $options['--include_disabled'] = 0; //active only
// $options['--date_range'] = date('Y-m-d H:i:s',strtotime("-1 days"));
$options['--include_disabled'] = 1; //include_disabled requested by Xixi on 6/6
}else if($this->option('interval') == 'weekly active'){
$options['--include_disabled'] = 0; //active only
}else if($this->option('interval') == 'weekly'){
$options['--include_disabled'] = 1;
}else{
}
// Run the export
$this->call('products:export', $options);
$last_run_export = ProductExport::where('notes', '=', $this->system_message)
->where('status', '=', 'finished')
->where('format', '=', 'distributor')
->orderBy('id', 'desc')
->firstOrFail();
$this->info('Export created successfully. Export ID is ' . $last_run_export->id);
$env = $this->option('env');
if ($env == NULL ){
$localdomain = 'site.com';
}else{
$localdomain = 'site';
}
$sftp_server = '1.1.1.1';
$sftp_user_name = 'site';
$sftp_user_pass = '######!';
// Open the SFTP connection
$connection = @ssh2_connect($sftp_server);
if (!$connection)
{
throw new Exception("Could not connect to $sftp_server.");
}
// Login to the SFTP server
if (! @ssh2_auth_password($connection, $sftp_user_name, $sftp_user_pass))
{
throw new Exception("Could not authenticate with username $sftp_user_name " .
"and password $sftp_user_pass.");
}
$sftp = @ssh2_sftp($connection);
if (!$sftp)
{
throw new Exception("Could not initialize SFTP subsystem.");
}
// Prepare the files
$source = '/home/forge/' . $localdomain . '/files/product-exports/' . $last_run_export->file_name;
if($this->option('interval') == 'daily'){
$destination = '/inbound/products/include_disabled_product' . $last_run_export->file_name;
}else if($this->option('interval') == 'daily active'){
$destination = '/inbound/products/active_only_product' . $last_run_export->file_name;
}else if($this->option('interval') == 'weekly active'){
$destination = '/inbound/products/weekly_active_only_full_product_' . $last_run_export->file_name;
}else if($this->option('interval') == 'weekly'){
$destination = '/inbound/products/weekly_include_disabled_full_product_' . $last_run_export->file_name;
}else{}
$this->info('Source: ' . $source);
$this->info('Destination: ' . $destination);
if (!file_exists('/inbound/products/')) {
ssh2_sftp_mkdir($sftp, '/inbound/products/', 0775, true);
}
if (file_exists($source)) {
chmod($source, 0775);
}else{
$this->info('$source NOT exist !');
}
// Upload the file
$stream = @fopen("ssh2.sftp://$sftp$destination", 'w');
if (!$stream)
{
throw new Exception("Could not open file: $destination");
}
$data_to_send = @file_get_contents($source);
if ($data_to_send === false)
{
throw new Exception("Could not open local file: $source.");
}
if (@fwrite($stream, $data_to_send) === false)
{
throw new Exception("Could not send data from file: $source.");
}
@fclose($stream);
// Delete the export when finished
if (file_exists(base_path() . ProductExport::path . $last_run_export->file_name))
{
unlink(base_path() . ProductExport::path . $last_run_export->file_name);
}
$last_run_export->delete();
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array();
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('interval', 'daily', InputOption::VALUE_REQUIRED,
'Export interval from option selected to now. Options are "daily", and "weekly".', 'daily'),
);
}
}
I checked my php.ini, and have updated to
└── cat php.ini | grep _max
log_errors_max_len = 1024
post_max_size = 2000M
upload_max_filesize = 2000M
session.gc_maxlifetime = 1440
; setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
┌──[root@iggy]──[/etc/php5/fpm]
└──
As you can see, I increase the memory allow to 2000M
already.
I also reboot my php-fpm right that
service php5-fpm restart
I still face the same issue, did I change the wrong file?
How do I double check ?
Questions
How would one go about and debug this further ?
I'm open to any suggestions at this moment.
Any hints/suggestions / helps on this be will be much appreciated!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2GvDIRn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire