Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Various problems with smarty when embedded in PHAR file

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Tue Apr 08, 2014 8:11 pm    Post subject: Various problems with smarty when embedded in PHAR file Reply with quote

Smarty experiences various problems when embedded within a PHAR file

Versions prior to 3.1.17 would cause php segfaults in both CLI and web mode particularly if the ioncube loader php (version 4.6) extension was enabled. With one minor hack to the smarty functions everything would work with ioncube enabled.

Versions 3.1.17 and 3.1.18 are unable to find templates in CLI or web mode, and generate an error. This behavior is independent of ioncube being enabled or not.

What's needed:
Smarty to function properly when embedded in a phar file, independent of whether or not (recent versions of) ioncube are enabled or not.

I've prepared a complete test setup for reproducing the issue. Including a build script for generating the .phar. You can download it at: https://dl.dropboxusercontent.com/u/19932814/smarty_phar_bug.tar.gz

The build environment was:
Ubuntu 13.10 with PHP 5.5.3

The test environment was:
Ubuntu 12.04 with PHP 5.3.10

You need php5 cli abilities to build the phar (named test.php)
The tar.gz file contains smarty 3.1.18

Details:
=======
Smarty 3.1.15
Smarty 3.1.16
(zend gaurd loader, and ioncube loader enabled in both web and CLI environments)
- CLI Mode: php Segfaults
- generating a core file and using gdb on the core indicates a stack overflow
when including files.
- Web mode: php segfaults

Smarty 3.1.17
Smarty 3.1.18
Tested with zend gaurd loader, and ioncube loader enabled in both web and CLI environments
Tested without zend guard loader, or ioncube loader in CLI environment
- CLI Mode:
PHP Fatal error: Uncaught --> Smarty: Unable to load template file 'extended.tpl' <--
thrown in phar:///var/www/test/phar_test/test.php/lib/Smarty/libs/sysplugins/smarty_internal_templatebase.php on line 127

- Web Mode:
- No output (white screen) different than chromes NO DATA RECIEVED)

Hints:
=====
In 3.1.15 I could get the phar to work with ioncube by changing:
include 'smarty_internal_parsetree.php';
to
include_once 'smarty_internal_parsetree.php';
in
smarty_internal_smartytemplatecompiler.php

Hoping you can help me figure this out so I can start distributing the app and it will work on most environments.
Back to top
View user's profile Send private message Visit poster's website
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Tue Apr 08, 2014 8:17 pm    Post subject: the code Reply with quote

Just to follow up.... I've attached the code I use to execute smarty (in the test phar app).

It 'finds' a temp directory, and creates a cache and templates_c directory
then instantiates smarty in the normal way.

The sample uses a simple case of template inheritance for testing.

Code:
<?php

$rootdir = dirname(__DIR__);
$tmpdir = '/tmp';
if( !$tmpdir || !is_dir($tmpdir) || !is_writable($tmpdir) ) die('no tmpdir');

require_once($rootdir.'/lib/Smarty/libs/Smarty.class.php');

@mkdir("$tmpdir/templates_c",0777,TRUE);
@mkdir("$tmpdir/cache",0777,TRUE);
touch("$tmpdir/cache/foo.txt");

$smarty = new Smarty();
$smarty->setTemplateDir("$rootdir/templates");
$smarty->setConfigDir("$rootdir/configs");
$smarty->setCompileDir("$tmpdir/templates_c");
$smarty->setCacheDir("$tmpdir/cache");

$smarty->assign('title','phar test');
$smarty->assign('text','This is a phar test 2');

//echo "DEBUG 1<br/>";
$smarty->display('extended.tpl'); // causes PHP segfault
//echo "DEBUG 2<br/>";

?>
Back to top
View user's profile Send private message Visit poster's website
edelacruz
Smarty Rookie


Joined: 10 May 2010
Posts: 25

PostPosted: Fri Jun 20, 2014 9:00 pm    Post subject: Reply with quote

I have smarty 3.1.17 running from phar with no problems. I don't remember doing anything special when I created the phar. I render templates both in php-cli and php-apache without any issues.

like I said I don't remember doing anything special when I created the phar. I can email you the phar if you want (I dont have it anywhere online or I'd post a link)
Back to top
View user's profile Send private message
edelacruz
Smarty Rookie


Joined: 10 May 2010
Posts: 25

PostPosted: Fri Jun 20, 2014 9:06 pm    Post subject: Reply with quote

Looking at my code to generate phar. Not sure if these flags matter (dont remember) but this is what I used:

Code:
$phar       = new \Phar($pharFilename, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, "$appName.phar");



Also iirc I did not set any entry point so nothing runs automatically on include. Hope this helps.

When implementing, I include smarty and point to specific resource (smarty class) like this:

Code:
require_once("phar://" . __DIR__ . "/Smarty3.1.17.phar/Smarty.class.php");


Everything seems to work perfectly.
Back to top
View user's profile Send private message
edelacruz
Smarty Rookie


Joined: 10 May 2010
Posts: 25

PostPosted: Fri Jun 20, 2014 9:11 pm    Post subject: Re: the code Reply with quote

EDIT:
I glanced at your code again and I think our use-cases might be slightly different. I put Smarty into a phar by itself and then include it from external script. It looks like you are trying to create a phar that contains both your app as well as Smarty all in one phar. File references inside of the phar should work exactly as they would if not embedded into a phar.
Anyways hopefully my replies will give you some clues.



What I wrote prior to edit:
---------------------

Sorry I should have been more concise in my reply's.

Try including using phar:// scheme instead of local disk.

So instead of:
Code:
require_once($rootdir.'/lib/Smarty/libs/Smarty.class.php');


Try something like this:
Code:
require_once('phar://'.$somepath.'smarty.phar/lib/Smarty/libs/Smarty.class.php');


And make sure you change all of smarty source code back to its original form. I suspect the changes you made were bandaging something which will just cause problems once you solve the actual issue.
Back to top
View user's profile Send private message
edelacruz
Smarty Rookie


Joined: 10 May 2010
Posts: 25

PostPosted: Fri Jun 20, 2014 9:22 pm    Post subject: Reply with quote

Another thing I notice:

dirname(__DIR__) is kind of strange. This will remove the last folder from the directory. Is that really what you meant to do?

Example:
if
__DIR__ = /var/www/mysite

then
dirname(__DIR__) = /var/www

I can't think of any good reason to ever pass a __DIR__ to dirname().
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP