How to clear user cache in APCu? - caching

I have tried to clear the user cache using this PHP code and access it from the browser:
<?php
apc_clear_cache();
apc_clear_cache('user');
apc_clear_cache('opcode');
echo json_encode(array(
'success' => true,
));
but it doesn't work.
(I am using these tools to see if it's working or not https://rtcamp.com/tutorials/php/zend-opcache/ )
Also when the user cache gets full, it doesn't restart from 0. The APCu just stops working.
I have tried to set apc.user_ttl=0, but APCu doesn't recognize it.
My settings are:
extension=apcu.so
apc.enabled=1
apc.shm_size=10240M
apc.ttl=7200
apc.enable_cli=1
apc.gc_ttl=3600
apc.entries_hint=4096
apc.slam_defense=0
apc.enable_cli = 1
apc.user_ttl=0
apc.serializer=igbinary

<?php
if (extension_loaded('apc')) {
echo "APC-User cache: " . apc_clear_cache('user') . "\n";
echo "APC-System cache: " . apc_clear_cache() . "\n";
}
if (extension_loaded('apcu')) {
echo "APCu cache: " . apcu_clear_cache() . "\n";
}
if (function_exists('opcache_reset')) {
// Clear it twice to avoid some internal issues...
opcache_reset();
opcache_reset();
}

The tool you are using is for Opcache, it doesn't know about APCu.
The script you need to look at the status of APCu is:
PHP 7: https://github.com/krakjoe/apcu/blob/master/apc.php
PHP 5: https://github.com/krakjoe/apcu/blob/PHP5/apc.php
If you believe you have found a bug, please report it on github.

Related

TCPDF ERROR joomla virtuemart does not create the invoice

I use joomla 3.9.6, virtuemart 3.4.2, and tcpdf 1.0.7
When i try to view the invoice(pdf) or when i change order status to confirmed i get the TCPDF ERROR: Unable to create output file: \vmorders\invoices\invoice_190522TIXG01.pdf
i already have created the folders vmorders\invoices and gave it the proper permissions. (the site runs locally with wamp)
Php Error log
[22-May-2019 16:11:21 UTC] PHP Warning: fopen(): remote host file access not supported, file://\vmorders\invoices\invoice_190522TIXG01.pdf in C:\wamp64\www\byzantinemusic\libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php on line 1854
I think i have found the solution. Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php". At line 1850 remove code
$filename = 'file://'.$filename;
and substitute with this
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath) .$filename;
For Virtuemart 3.6.10:
Edit "libraries\vendor\tecnickcom\tcpdf\include\tcpdf_static.php".
At line 1817 remove code:
$filename = 'file://'.$filename;
and replace with:
$filename = $filename;
$absPath = getcwd();
$filename = str_replace("\\administrator","",$absPath)."/".$filename;

making shell zip accessible to php

Hi got a LEMP stack un Ubuntu 18.04 with php 7.2.5
server info says
Shell Exec Is Supported
Shell Exec Zip Not Supported
therefore some of my plugins says
This server is not configured for the Shell Zip engine - please use a different engine mode. To make 'Shell Zip' available, ask your host to:
1. Install the zip executable and make it accessible to PHP.
I have tries this code
PHP - How to know if server allows shell_exec
if(function_exists('shell_exec')) {
echo "exec is enabled";
}
and the function is enabled
however when i test if it is executable with the code below nothing happens.
As DanFromGermany pointed out, you probably check then if it is
executable. Something like this would do it
if(shell_exec('echo foobar') == 'foobar'){
echo 'shell_exec works';
}
or tried this, returns nothing as well just white page
// Exec function exists.
// Exec is not disabled.
// Safe Mode is not on.
$exec_enabled =
function_exists('exec') &&
!in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions')))) &&
strtolower(ini_get('safe_mode')) != 1
;
if($exec_enabled) { exec('blah'); }
I have also checked with the code below from https://wpguru.co.uk/2014/01/how-to-test-if-a-shell-command-will-work-in-php/ and it does work
// helper function
function checkShellCommand($command) {
$returnValue = shell_exec("$command");
if(empty($returnValue)) {
return false;
} else {
return true;
}
}
// test the shell command you'd like to use
if (!checkShellCommand('uname -a')) {
print 'This command cannot be executed.';
} else {
echo shell_exec('uname -a');
}
So, could anyone tell me how can I make it accessible to PHP
Many thanks
this was solved by
apt-get install zip unzip

Import big csv in Laravel

I'm using following package to import large CSV file to MySQL database:
https://github.com/Maatwebsite/Laravel-Excel
Here is my controller code:
Excel::filter('chunk')->load($file)->chunk(250, function($results) use ($count)
{
++$count;
echo "<br/> Count = " . $count;
foreach($results as $row)
{
// do stuff
}
Here is line from composer.json
"maatwebsite/excel": "~2.1.0"
Here is my config/app.php file:
'providers' => [
....
....
Maatwebsite\Excel\ExcelServiceProvider::class,
],
'aliases' => [
....
....
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]
I am getting this error and I cannot find any solution:
InvalidArgumentException in Dispatcher.php line 333:
No handler registered for command [Maatwebsite\Excel\Readers\ChunkedReadJob]
I tried following link for solution but no luck:
https://github.com/Maatwebsite/Laravel-Excel/issues/957
https://github.com/Maatwebsite/Laravel-Excel/issues/952
Are you doing some manipulations for each row of csv before inserting into the database or is it like you need to import the data directly to the database?
Just a quick tip, its your csv is in the sequence how your database table columns are ordered, you can use ubuntu terminal to import larger files :
mysql -uroot -proot --local_infile=1 3parsfdb -e "LOAD DATA LOCAL INFILE '/logfiles/Bat_res.csv' INTO TABLE Bat_res FIELDS TERMINATED BY ','"
If this is something which you want to do programatically or in cron, then you need this package. Can you try clearing laravel cache and also try
composer dump-autoload
One more thing is to ensure there are no special characters in the csv which can not get imported.
Instead of that package, try the LOAD DATA INFILE MySQL procedure, using Laravel's DB object. Here is an example.
I used this for importing big sized csv files (300M-400M) into a mysql db and worked for me.
LOAD DATA LOCAL INFILE! I really missed MySQL, I used this to ingest a huge CVS file, about 6gb in our server, this took about 20 mins.
You can use something like this:
private function importData(int $ignoreLines, string $fileName) : void
{
//$this->setLOG("Importing data, please wait", "i");
$table = 'npdata_csvfile_temp';
$importDB = "LOAD DATA LOCAL INFILE '$fileName' ";
$importDB .= "INTO TABLE $table ";
$importDB .= "COLUMNS TERMINATED BY ',' ";
$importDB .= 'OPTIONALLY ENCLOSED BY "\""';
$importDB .= "LINES TERMINATED BY '\\n' ";
$importDB .= "IGNORE $ignoreLines LINES ";
DB::connection()->getpdo()->exec($importDB);
//$this->setLOG("Done with importing data", "i");
}

Magento 1.8.1: media directory bug if using symlink

I am having trouble with my Magento install, in the CMS when I go to insert an image with the wysiwig editor the folder keeps opening repeatedly.
The folder structure should be:
- infortis
- brands
- fortis
- ultimo
But what I get is:
-infortis
-infortis
-infortis
-infortis
-infortis
And this just keeps repeating.
Magento Version 1.8.1. Any help appreciated.
I have found that the following edits makes it work as expected, and works with non-symlinked (dev) resources as well:
In the same class as mentiond Mage_Cms_Helper_Wysiwyg_Images, apply these patches:
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>Images.php (<b>Today 4:14:50 PM</b>)</html>
+++ <html><b>Current File</b></html>
## -223,7 +223,7 ##
public function getCurrentUrl()
{
if (!$this->_currentUrl) {
- $path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath());
+ $path = str_replace(realpath(Mage::getConfig()->getOptions()->getMediaDir()), '', $this->getCurrentPath());
$path = trim($path, DS);
$this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
$this->convertPathToUrl($path) . '/';
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>Images.php (<b>f47f0ff</b>)</html>
+++ <html><b>Current File</b></html>
## -68,7 +68,7 ##
*/
public function getStorageRoot()
{
- return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
+ return realpath(Mage::getConfig()->getOptions()->getMediaDir()) . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
. DS;
}
Found the issue in Mage_Cms_Helper_Wysiwyg_Images::convertIdToPath
The core code is as follows.
public function convertIdToPath($id)
{
$path = $this->idDecode($id);
if (!strstr($path, $this->getStorageRoot())) {
$path = $this->getStorageRoot() . $path;
}
return $path;
}
And the fix is to use realpath when getting the storage root as follows.
public function convertIdToPath($id)
{
$path = $this->idDecode($id);
$realpath = $this->getStorageRoot();
if (is_link(rtrim($realpath,'/'))) {
$realpath = realpath($realpath);
}
if (!strstr($path, $realpath)) {
$path = $realpath . $path;
}
return $path;
}
So what we have done is to rewrite Mage_Cms_Helper_Wysiwyg_Images and use the updated converIdToPath function. I found the original solution on a German website, but that will break if say you have a dev system without links and another system with a link.
We recently ran into this issue as well and I wanted to share a little more info to save the next person some time. If you are running the Magento Enterprise Edition and have an active support agreement in place there is an official patch available. Just open a support ticket and request the patch directly. The patch name is "PATCH_SUPEE-2662_EE_1.13.1.0_v1".

" URL not found 404 error" after the 3rd page during Magento installation

I have been trying to install Magento 1.6 latest version and sample data magento sample-data- 1.1.2 but all in vain.I cannot get past the 3rd page,where database,username,URL etc information is added.When I click the continue button,I get 404 error “URL not found“ .After google search I found out that some guys reported similar problems that lead to some php files accessing the Mysql server.Those files seemed to have a syntax error of some kind.My problem is of similar nature but leads to a diffrent php file having an 'an access voilation'error.The url points to the report directory inside magento/var.
This is my report file in Public_html/magento/var/report
a:5:{i:0;s:223:"Error in file: "/home/archy/public_html/magento/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.2-0.8.3.php" - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'AX' for key 'PRIMARY'";i:1;s:1022:"#0 /home/archy/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php(645): Mage::exception('Mage_Core', 'Error in file: ...')
I don’t understand how to solve the problem.Has anyone experienced similar problems.
New Addition..
I am really struggling with Magento!! I tried to install magento on my desktop(local server) after a failed attempt on my laptop(above).But I get I "Object not found error 404" after clicking the continue button in the configuration section of my installation.I have double checked my permissions on media, var,app directories.They are all 777.Sample date was installed before starting installation.The only option that I commented out in .htaccess was the the ExpireDefault which was causing "Internal Server Error"before being removed.
Here is the stack trace:
Mage_Core_Exception: Can't retrieve entity config: sales/quote_shipping_rate in /home/sam/public_html/magento/app/Mage.php on line 563
Call Stack:
0.0296 644264 1. {main}() /home/sam/public_html/magento/index.php:0
0.1808 1129872 2. Mage::run() /home/sam/public_html/magento/index.php:80
0.3326 2771544 3. Mage_Core_Model_App->run() /home/sam/public_html/magento/app/Mage.php:640
1.0335 4165088 4. Mage_Core_Model_App->_initModules() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/App.php:338
5.2513 4490984 5. Mage_Core_Model_Resource_Setup::applyAllUpdates() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/App.php:412
7.1161 9860936 6. Mage_Core_Model_Resource_Setup->applyUpdates() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php:235
7.1163 9861520 7. Mage_Core_Model_Resource_Setup->_upgradeResourceDb() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php:320
7.1163 9861600 8. Mage_Core_Model_Resource_Setup->_modifyResourceDb() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php:437
7.1792 9917352 9. include('/home/sam/public_html/magento/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php') /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php:624
7.1810 9918112 10. Mage_Sales_Model_Resource_Setup->addAttribute() /home/sam/public_html/magento/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php:32
7.1810 9918112 11. Mage_Sales_Model_Resource_Setup->_flatTableExist() /home/sam/public_html/magento/app/code/core/Mage/Sales/Model/Resource/Setup.php:101
12.4649 9964680 12. Mage_Core_Model_Resource_Setup->getTable() /home/sam/public_html/magento/app/code/core/Mage/Sales/Model/Resource/Setup.php:87
12.4649 9964680 13. Mage_Core_Model_Resource->getTableName() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource/Setup.php:184
12.5666 10576032 14. Mage::throwException() /home/sam/public_html/magento/app/code/core/Mage/Core/Model/Resource.php:272
)
I couldn't find out what could have caused the problem.Help needed.
Thank you.
Check with the below script if your server or local meets the requirement to install magento
function extension_check($extensions) {
$fail = '';
if(version_compare(phpversion(), '5.2.0', '<')) {
$fail .= '<li>PHP 5.2.0 (or greater)</li>';
}
if(!ini_get('safe_mode')) {
if(preg_match('/[0-9].[0-9]+.[0-9]+/', shell_exec('mysql -V'), $version)) {
if(version_compare($version[0], '4.1.20', '<')) {
$fail .= '<li>MySQL 4.1.20 (or greater)</li>';
}
}
}
foreach($extensions as $extension) {
if(!extension_loaded($extension)) {
$fail .= '<li>'.$extension.'</li>';
}
}
if($fail) {
echo '<p>Your server does not meet the requirements for Magento.';
echo 'The following requirements failed:</p>';
echo '<ul>'.$fail.'</ul>';
} else {
echo '<p>Congratulations! Your server meets the requirements for Magento.</p>';
}
}
?>
STEP 2 : CHeck Max Execution time
Step 3: Install the Magento again with the version 1.6.0.0 as there were some problem at the first release or try with latest version 1.6.2.0
Let me know if it works or not

Resources