PHP try catch not working with Zend cache Exception - php

I have this code to start Zend Cache , and I set the try cache exception to cancel Zend Cache if an error accorded during the process, but it does not work and does not print the error inside catch Exception.
$frontendOptions = array(
'lifetime' => $cacheTime,
'content_type_memorization' => false,
'default_options' => array(
'cache' => true,
'make_id_with_cookie_variables' => false,
'make_id_with_session_variables' => false,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_files_variables' => true,
'cache_with_cookie_variables' => true,
'tags' => $cacheTag,
),
'regexps' => array(
'$' => array('cache' => true),
)
);
$backendOptions = array('cache_dir' => '/var');
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
try {
$cache->start();
} catch (Exception $exc) {
echo $exc->getMessage();
}
and I tried the $cache->cancel() without any result.
Thanks

Related

PHP/Laravel looks like we got no XML document when making soapcall

I am trying to do a soap call and I keep getting the following error:
looks like we got no XML document
EDIT error message
here's an example that works fine in my SOAP UI
Here's my array that I send to my soapCall:
$params = [
'id' => '0000002721',
'options' => [
'returnAttachments' => 'false',
'returnPictures' => 'false',
'returnContract' => 'false'
]
];
Here is the code how I make the soap call
try {
$options = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$context = stream_context_create($options);
$soapClient = new SoapClient(__DIR__ . '/Soap.wsdl', [
'stream_context' => $context,
'login' => 'login',
'password' => 'password',
'trace' => 1,
'exceptions' => true,
]);
$soapClient->__setLocation('url');
$this->soapClient = $soapClient;
} catch (\SoapFault $e) {
var_dump($e); exit;
}
try {
$result = $this->soapClient->__soapCall('getMaintenanceObject', $params);
} catch (\SoapFault $e) {
var_dump($e); exit;
}
SoapClient can be not very expressive when it comes to displaying the errors, add this:
var_dump($this->soapClient->__getLastRequestHeaders());
var_dump($this->soapClient->__getLastResponseHeaders());

Dompdf package for Laravel 4 return 500 when many ( >9 ) pages are generated

I'm using this Dompdf package for Laravel 4 by Jonathan Thuau
and I'm getting server error whenever I try to generate more than 9 gapes otherwise it works.
Below is the screenshot of the error
Below is also my config file , let me know if I have to change anything in that
return array(
'DOMPDF_TEMP_DIR' => sys_get_temp_dir(),
'DOMPDF_UNICODE_ENABLED' => true,
'DOMPDF_PDF_BACKEND' => 'CPDF',
'DOMPDF_DEFAULT_MEDIA_TYPE' => 'screen',
'DOMPDF_DEFAULT_PAPER_SIZE' => 'letter',
'DOMPDF_DEFAULT_FONT' => 'serif',
'DOMPDF_DPI' => 96,
'DOMPDF_ENABLE_PHP' => false,
'DOMPDF_ENABLE_REMOTE' => false,
'DOMPDF_ENABLE_CSS_FLOAT' => false,
'DOMPDF_ENABLE_JAVASCRIPT' => true,
'DEBUGPNG' => false,
'DEBUGKEEPTEMP' => false,
'DEBUGCSS' => false,
'DEBUG_LAYOUT' => false,
'DEBUG_LAYOUT_LINES' => true,
'DEBUG_LAYOUT_BLOCKS' => true,
'DEBUG_LAYOUT_INLINE' => true,
'DOMPDF_FONT_HEIGHT_RATIO' => 1.1,
'DEBUG_LAYOUT_PADDINGBOX' => true,
'DOMPDF_ENABLE_HTML5PARSER' => false,
'DOMPDF_ENABLE_FONTSUBSETTING' => false,
'DOMPDF_ADMIN_USERNAME' => 'user',
'DOMPDF_ADMIN_PASSWORD' => 'password',
);
The error was due to resource exhaustion and I have to add to following lines on top of the page and it worked
set_time_limit(0);
ini_set("memory_limit",-1);
ini_set('max_execution_time', 0);

Bad characters when generating pdf file with Knp Snappy

I am using Symfony2. When the pdf file is generated using this code :
public function printAction($id)
{
// initialiser $demande
$html = $this->renderView('PFETimeBundle:Demande:print.html.twig',
array('demande'=> $demande)
);
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
I get this content (french characters appear in bad characters) :
try to add the encoding property
'encoding' => 'utf-8',
heres a full copy of my working code, pls note that i pass an options array as second argument to getOutPutFromHtml()
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html, array(
'orientation' => 'landscape',
'enable-javascript' => true,
'javascript-delay' => 1000,
'no-stop-slow-scripts' => true,
'no-background' => false,
'lowquality' => false,
'encoding' => 'utf-8',
'images' => true,
'cookie' => array(),
'dpi' => 300,
'image-dpi' => 300,
'enable-external-links' => true,
'enable-internal-links' => true
)),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="report.pdf"'
)
);
If you are using the generateFromHtml method, you have to use it like this, at third parameter:
$this->container->get('knp_snappy.pdf')->generateFromHtml(
$this->container->get('templating')->render(
'YourBundle:Template:pdfTemplate.html.twig',
array(
'var' => $var,
)
),
'/path/to/file.pdf',
array(
'encoding' => 'utf-8',
)
);

Allowing YouTube embed with HTMLPurifier on Laravel 4 and mewebstudio/Purifier

I'm using the mewebstudio/Purifier package service provider HTMLPurifier on Laravel 4.2.
For some reason I can't make the youtube iframe feature work. I even tried the author example for enabling it with no luck.
This is my HTMLPurifier bundle config:
return array(
'encoding' => 'UTF-8',
'finalize' => true,
'preload' => false,
'settings' => array(
'default' => array(
'HTML.Doctype' => 'XHTML 1.0 Strict',
'HTML.Allowed' => 'div[style],b,strong,i,em,a[href|title|style],ul,ol,li,p[style],br,span[style],
img[width|height|alt|src],h1[style],h2[style],h3[style],h4[style],h5[style],table[class|style|summary],tr,td[abbr],tbody,thead',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
'HTML.SafeObject' => true,
'Output.FlashCompat' => true,
'HTML.SafeIframe' => true,
'URI.SafeIframeRegexp' => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
'HTML.Nofollow' => true,
'URI.Host' => 'domain.com',
),
),
);
And this is my test in routes:
Route::get('/clean', function() {
$pured = Purifier::clean('<iframe src="//www.youtube.com/embed/gLUdqi8J0mQ" width="640" height="360" frameborder="0"></iframe>', 'default');
return $pured;
});
Everything else works, but this.
Thanks fellow warriors :)
HTMLPurifier already has a filter ready-made for Youtube videos, make sure you use it.
To use it make sure you have this line on your config:
'Filter.YouTube' => true
Your final config file would look like this:
return array(
'encoding' => 'UTF-8',
'finalize' => true,
'preload' => false,
'settings' => array(
'default' => array(
'HTML.Doctype' => 'XHTML 1.0 Strict',
'HTML.Allowed' => 'div[style],b,strong,i,em,a[href|title|style],ul,ol,li,p[style],br,span[style],
img[width|height|alt|src],h1[style],h2[style],h3[style],h4[style],h5[style],table[class|style|summary],tr,td[abbr],tbody,thead',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
'HTML.SafeObject' => true,
'Output.FlashCompat' => true,
'HTML.SafeIframe' => true,
'URI.SafeIframeRegexp' => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
'HTML.Nofollow' => true,
'URI.Host' => 'domain.com',
'Filter.YouTube' => true
),
),
);

Zend Cache Front end

I'm using this function in Bootstrap.php to cache my controllers , and i need to cache some controllers only I don't need to cache index controller and article controller as an example
and i need to cache question controller but it does not working . this function is cached all my controllers
protected function _initCache()
{
mb_internal_encoding("UTF-8");
$dir = "/var/www/data/cache/all";
$frontendOptions = array(
'lifetime' => 3600,
'content_type_memorization' => true,
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
),
'regexps' => array(
'^/$' => array('cache' => false),
"^/question/" => array('cache' => true),
"^/article/" => array('cache' => false),
)
);
$backendOptions = array(
'cache_dir' =>$dir
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
}
so what i can do I tried all soluations please help me.
Thanks
Create a controller plugin with that code, and detect the request.
Something like...
if($request->getControllerName() == 'index' || ... == 'article') {
return;
}
mb_internal_encoding("UTF-8");
...

Categories