Symfony2 :500 Internal error on assetic generated file in dev mode - symfony

I use assetic on my Symfony2 project and when i put my project on a new server environement i have the following 500 internal Server Error on the top of the CSS and JS generated files on dev environement. It seems that assetic can't access to the temp directory to generate the file.
[exception] 500 | Internal Server Error | ErrorException
[message] Warning: file_put_contents(): Filename cannot be empty in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
[1] ErrorException: Warning: file_put_contents(): Filename cannot be empty in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
at n/a
in /Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 92
at Symfony\Component\HttpKernel\Debug\ErrorHandler->handle('2', 'file_put_contents(): Filename cannot be empty', '/Users/jo/Developpement/coV2/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php', '92', array('content' => '/*!
The line 92 of the BaseCompressorFilter class is the last line of this code :
$tempDir = realpath(sys_get_temp_dir());
$input = tempnam($tempDir, 'YUI-IN-');
$output = tempnam($tempDir, 'YUI-OUT-');
file_put_contents($input, $content);
$tempDir is ok, but $input is empty.
Any idea ?

Related

PhpStorm with PHPUnit 8.4 gives exception Uncaught PHPUnit\Runner\Exception class ... could not be found

I tried to use PHPUnit v8. However I was not succeeded with PhpStorm. When I run simple test (class method) in PhpStorm I got the following message:
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Mrself\\TreeType\\Tests\\Functional\\BuildingTest' could not be found in '/vagrant/symfony-tree-type/tests/Functional/BuildingTest.php'. in /vagrant/symfony-tree-type/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:65
Yes, I have that class and yes I have psr configured properly:
"autoload": {
"psr-4": {
"Mrself\\TreeType\\": "./src/"
}
},
"autoload-dev": {
"psr-4": {
"Mrself\\TreeType\\Tests\\": "./tests/"
}
}
The proof the I have everything correctly setup is that when I run vendor/bin/phpunit it gives me correct result.
When I run method in PhpStorm I got the following call:
/usr/bin/php /vagrant/symfony-tree-type/vendor/phpunit/phpunit/phpunit --configuration /vagrant/symfony-tree-type/phpunit.xml --filter "/(::testFormCanBeBuild)( .*)?$/" Mrself\\TreeType\\Tests\\Functional\\BuildingTest /vagrant/symfony-tree-type/tests/Functional/BuildingTest.php --teamcity
However if I prepend class namespace with \\ everything works correctly as well. I can not get a clue what's going on. PHPUnit version 7 works as well.
Same thing happened to me. All of the sudden I started getting the following error:
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Tests\\Feature\\ExampleTest' could not be found
And after I have read #frank-vue's comment I noticed the same thing and he did: If I run tests on the entire folder it runs normally, but if I run test on a specific class/method I get that error.
I tried earlier version of PHPStorm, downgraded PHP plugin etc... and nothing worked.
In my case, when I checked the stacktrace looks like:
#0 /var/www/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(145): PHPUnit\Runner\StandardTestSuiteLoader->load('Tests\\\\Unit\\\\Ex...', '/var/www/tests/...')
#1 /var/www/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(105): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('Tests\\\\Unit\\\\Ex...', '/var/www/tests/...')
#2 /var/www/vendor/phpunit/phpunit/src/TextUI/Command.php(177): PHPUnit\Runner\BaseTestRunner->getTest('Tests\\\\Unit\\\\Ex...', '/var/www/tests/...', Array)
#3 /var/www/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)
#4 /var/www/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in /var/www/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php on line 69
Notice Tests\\\\Unit\\\\Ex... instead of Tests\\Unit\\Ex....
So in the end I broke the rule and I've modified vendor file, which should be avoided at any cost, but as a temporary solution it solves my problem.
So I added 1 line to the vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php on line 98 (PHPUnit version 8.4.1), which replaces unnecessary '\'s.
if (empty($suiteClassFile) && \is_dir($suiteClassName) && !\is_file($suiteClassName . '.php')) {
/** #var string[] $files */
$files = (new FileIteratorFacade)->getFilesAsArray(
$suiteClassName,
$suffixes
);
$suite = new TestSuite($suiteClassName);
$suite->addTestFiles($files);
return $suite;
}
$suiteClassName = str_replace('\\\\', '\\', $suiteClassName); // THIS IS THE LINE I ADDED
try {
$testClass = $this->loadSuiteClass(
$suiteClassName,
$suiteClassFile
);
} catch (Exception $e) {
$this->runFailed($e->getMessage());
return null;
}

unable to load file from url phpoffice/spreadsheet

Trying to load an .xlsx file from url but it gives error like,
Fatal error: Uncaught InvalidArgumentException: File
"http://localhost/test/csvfile/samplesms.xlsx" does not exist. in
D:\wamp\www\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Shared\File.php on line 137
Loading file with below,
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load($filename);
File is already at given location.
you can load file content using php_get_content or curl and save it temporary locally then load local version of the file
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$file = file_get_contents($filename);
$inputFileName = 'tempfile.xlsx';
file_put_contents($inputFileName, $file);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
loading from URL is not supported in phpoffice/spreadsheet.

wordpress: Uncaught Error: Call to undefined function mb_internal_encoding()

I have just installed equifax-credit-check plugin in my wordpress site.Now this error displayed
Fatal error: Uncaught Error: Call to undefined function mb_internal_encoding() in /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/vendor/danielstjules/stringy/src/Stringy.php:58 Stack trace: #0 /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/vendor/danielstjules/stringy/src/Create.php(17): Stringy\Stringy->__construct('/reportlink/das...', NULL) #1 /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/class/App.php(179): Stringy\create('/reportlink/das...') #2 /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/class/PluginCore.php(300): Baerr\App\App::is_dashboard() #3 /home/uplogictecz/public_html/demo/reportlink/wp-includes/class-wp-hook.php(298): Baerr\App\PluginCore->dashboard_access_control('') #4 /home/uplogictecz/public_html/demo/reportlink/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(false, Array) #5 /home/uplogictecz/public_html/demo/reportlink/wp-includes/pl in /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/vendor/danielstjules/stringy/src/Stringy.php on line 58
In my /home/uplogictecz/public_html/demo/reportlink/wp-content/plugins/equifax-credit-check/vendor/danielstjules/stringy/src/Stringy.php on line 58
Line function is
public function __construct($str = '', $encoding = null)
{
if (is_array($str)) {
throw new InvalidArgumentException(
'Passed value cannot be an array'
);
} elseif (is_object($str) && !method_exists($str, '__toString')) {
throw new InvalidArgumentException(
'Passed object must have a __toString method'
);
}
$this->str = (string) $str;
$this->encoding = $encoding ?: \mb_internal_encoding();
}
This line is $this->encoding = $encoding ?: \mb_internal_encoding(); no 58.
How to fix this issue ?.Kindly check it.
Your PHP environment is missing MBSTRING extension. It is normal, as mbstring is not built-in default extension in some PHP installations. You can install it if you have an access to your server:
For PHP 5.* and Debian
sudo apt-get install php-mbstring
For PHP 5.* and Fedora
yum install php-mbstring
For PHP 7.0, use
sudo apt-get install php7.0-mbstring
And of course, if you don't have server access, you need to ask your hosting provider to enable this extension for your website server.

ZipArchive::close(): Renaming temporary file failed: Invalid argument Phpexcel Laravel

I am working on append excel content into existing excel file and save it in a predefined directory with different name. I am using the Laravel 5.4 framework for my application.
I am using the below code to create excel file and save it on specified location:
$objPHPExcel = \PHPExcel_IOFactory::createReader('Excel2007');
//Load Existing excel file into I want to append
$objPHPExcel = $objPHPExcel->load(getDocumentPath().'/Report_Template_UG.xlsx');
$objPHPExcel->setActiveSheetIndex(0);
//Here I have Written code to insert my data into loaded excel file
$today = date('d-m-Y');
$time = date('H:i:s');
$filename = 'Report_'.$today.' '.$time.'.xlsx';
//welcomed is the root directory name of laravel project
$dir = 'C:\xampp\htdocs\welcomed\storage\documents\';
$filepath = $dir . $filename;
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($path);
On executing the above code, I am gettign the below error:
ErrorException in Excel2007.php line 377:
ZipArchive::close(): Renaming temporary file failed: Invalid argument
Can anyone please tell me, What I have done wrong in above code or do I have missed something?
Thanks

Symfony 2 assetic:dump UglifyCss causes [Symfony\Component\Process\Exception\RuntimeException] The process has been signaled with signal "5"

I'm developing my first Symfony 2 app, and I'm trying Uglify to minimize my .css files. The problem is that when I execute the command:
$ /Applications/mampstack-5.4.17-0/php/bin/php app/console assetic:dump --verbose
I get the following result:
Dumping all dev assets.
Debug mode is on.
17:22:09 [file+] /Users/bender22/Proyectos/ETraining/app/../web/examlayout.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam3.css
[Symfony\Component\Process\Exception\RuntimeException]
The process has been signaled with signal "5".
Exception trace:
() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:428
Symfony\Component\Process\Process->wait() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:204
Symfony\Component\Process\Process->run() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter/UglifyCssFilter.php:106
Assetic\Filter\UglifyCssFilter->filterDump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter/FilterCollection.php:69
Assetic\Filter\FilterCollection->filterDump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset/BaseAsset.php:108
Assetic\Asset\BaseAsset->dump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset/AssetCollection.php:151
Assetic\Asset\AssetCollection->dump() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:222
Symfony\Bundle\AsseticBundle\Command\DumpCommand->doDump() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:162
Symfony\Bundle\AsseticBundle\Command\DumpCommand->dumpAsset() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:61
Symfony\Bundle\AsseticBundle\Command\DumpCommand->execute() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244
Symfony\Component\Console\Command\Command->run() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:904
Symfony\Component\Console\Application->doRunCommand() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
Symfony\Component\Console\Application->doRun() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:85
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
Symfony\Component\Console\Application->run() at /Users/bender22/Proyectos/ETraining/app/console:27
My environment:
OS: Mac OS 10.8.4
Symfony: 2.3.2
symfony/assetic-bundle: 2.3.0
kriswallsmith/assetic: 1.1.2
Bitnami Mampstack: 5.4.17
Node.js: 0.10.13
Php: 5.4.17
Apache: 2.4.4
Here are some relevant information:
My config.yml:
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ExamBundle]
java: /usr/bin/java
filters:
cssrewrite: ~
uglifyjs2: # the path to the uglifyjs executable
bin: /usr/local/bin/uglifyjs
node: /usr/local/bin/node
uglifycss: # the path to the uglifycss executable
bin: /usr/local/bin/uglifycss
node: /usr/local/bin/node
My Twig template:
{% block stylesheets %}
{% stylesheets output='css/generated/examlayout.css' filter='cssrewrite, uglifycss' debug=false
'bundles/exam/css/exam.css'
'bundles/exam/css/exam3.css'
%}
<link href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
{% endblock %}
Some of the things that I've already tested without any luck:
1) Execute the command (without specify /Applications/mampstack-5.4.17-0/php/bin/php )
$ app/console assetic:dump --verbose
The result is
Dumping all dev assets.
Debug mode is on.
17:55:12 [file+] /Users/bender22/Proyectos/ETraining/app/../web/css/generated/examlayout.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam3.css
The result file in web/css is correct (the content includes both .css files minimized). The problem is that when I load the Web page, the .css is broken:
<link href="/app_dev.php/css/generated/examlayout.css" rel="stylesheet" />
and if I click on the href, the content the browser shows is:
/*
[exception] 500 | Internal Server Error | Symfony\Component\Process\Exception\RuntimeException
[message] The process has been signaled with signal "5".
[1] Symfony\Component\Process\Exception\RuntimeException: The process has been signaled with
signal "5".
at n/a
in /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process
/Process.php line 428
at Symfony\Component\Process\Process->wait(null)
in /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process
/Process.php line 204
at Symfony\Component\Process\Process->run()
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter
/UglifyCssFilter.php line 106
at Assetic\Filter\UglifyCssFilter->filterDump(object(FileAsset))
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter
/FilterCollection.php line 69
at Assetic\Filter\FilterCollection->filterDump(object(FileAsset))
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/BaseAsset.php line 108
at Assetic\Asset\BaseAsset->dump(null)
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/AssetCollection.php line 151
at Assetic\Asset\AssetCollection->dump(null)
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/AssetCache.php line 69
at Assetic\Asset\AssetCache->dump()
in /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle
/AsseticBundle/Controller/AsseticController.php line 88
at Symfony\Bundle\AsseticBundle\Controller\AsseticController->render('6a1dad3',
null)
in line
at call_user_func_array(array(object(AsseticController), 'render'),
array('6a1dad3', null))
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2774
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2748
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2878
at Symfony\Component\HttpKernel\DependencyInjection
\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2179
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /Users/bender22/Proyectos/ETraining/web/app_dev.php line 28
*/
2) Set folder privileges with (in a recursive way):
chmod 777
for the folders:
web (inside my Symfony project) and my temp folder, which turns out to be:
/var/folders/hp/vv24wsq56bs9szlt7j8bt3600000gn/T
Could you please help me out to solve this? I've ran out of ideas.
Note: I've tagged this as uglifyjs2 because I don't have enough points for creating the tag uglifycss
Thanks in advance :)
We had the same issue with the uglifycss filter running out of memory with big css files without a proper error message.
You can show the exact error message by following the following steps:
disable uglifycss filter in your assetic configuration
run assetic:dump task
navigate to the dir where the css files are generated, probably web/css
run uglifycss <filename> > test.css for each generated css file
see which file returns an error
We solved our issue by overriding the UglifyCssFilter class and adding a custom Node.js parameter for a higher memory limit:
<?php
namespace Acme\DemoBundle\Filter;
use Assetic\Filter\UglifyCssFilter as BaseUglifyCssFilter;
class UglifyCssFilter extends BaseUglifyCssFilter
{
protected function createProcessBuilder(array $arguments = array())
{
if ($arguments[0] === '/usr/bin/node') {
$arguments = array_merge(array(
$arguments[0],
'--max-old-space-size=4096'
), array_slice($arguments, 1));
}
return parent::createProcessBuilder($arguments);
}
}
You have to change the Node path to the correct location (or improve the comparison in some other way).
You can let Assetic use this class by setting a service parameter in your config file:
parameters:
assetic.filter.uglifycss.class: Acme\DemoBundle\Filter\UglifyCssFilter

Resources