Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2020-06-08 16:04:53

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,767
GitHub

Re: strftime unix %s doesn't works on localhost

Bloke wrote #323644:

Perhaps so we can rule out or confirm PHP 7.4, that might be useful. Thank you.

OK, I’ll wait until the latest compile has finished, then push a 7.3 latest compile through, and I’ll update this thread. ETA: within the hour.

Offline

#17 2020-06-08 16:07:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

This particular issue is easy to work around as I mentioned in a previous post. Just return the posted + time zone value directly. The only time that wouldn’t work is if somebody used %s as part of a wider format string, e.g.:

<txp:posted format="%s (%F %T)" />

Can’t see anybody doing that, but to guard against that, it might be prudent to just do a str_replace() of ‘%s’ for the time+timezone, so it never passes %s through the strftime() function. I can’t see any downside to doing that and if it is a PHP bug, we won’t care when they fix it as we won’t be using that feature anyway.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#18 2020-06-08 16:08:14

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,767
GitHub

Re: strftime unix %s doesn't works on localhost

Actually, PHP 7.3 is already latest – release-demo now on PHP 7.3.18

Last edited by gaekwad (2020-06-08 16:08:25)

Offline

#19 2020-06-08 16:13:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

Even more bizarre:

dmp('DIRECT', strftime('%s', '1591628404'));
dmp('GM DIRECT', gmstrftime('%s', '1591628404'));

Expected:
DIRECT 1591628404
GM DIRECT 1591628404

Actual:
DIRECT -1
GM DIRECT 1591628404

?!!?!?!?!?

So if you add the gmt attribute to your <txp:posted /> tag, it works fine.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#20 2020-06-08 16:20:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

gaekwad wrote #323648:

Actually, PHP 7.3 is already latest – release-demo now on PHP 7.3.18

In which case, short of heavy caching getting in the way, this issue occurs on PHP 7.3 as well?!

EDIT: but on my DO droplet running PHP 7.3.18-1+ubuntu16.04.1+deb.sury.org+1, it returns correct values. No -1 in sight. *head scratch*

Look at the source of the release-demo welcome article and search it for ‘posted’ to see the debug output. The RESULT is what is returned from the various function calls. Text in ALL CAPS indicates what’s being tested.

Last edited by Bloke (2020-06-08 16:26:13)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#21 2020-06-08 16:34:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

So is it an environment thing?

Demo server:

Textpattern version: 4.8.1 (8e4e0ea0982f48cbe19bbb00c4c260a2)
Last update: 2020-06-08 15:00:02
Textpattern path: __TXP-ROOT/textpattern
Article URL pattern: section_title
Production status: testing
Temporary directory path: __TXP-ROOT/textpattern/tmp
PHP version: 7.3.18
GD Graphics Library: bundled (2.1.0 compatible); Supported formats: GIF, JPEG, PNG, WebP.
Server timezone: Europe/Amsterdam
Server local time: 2020-06-08 18:26:26
Daylight Saving Time enabled?: 1
Automatically adjust Daylight Saving Time setting?: 1
Time zone (GMT offset in seconds): Europe/Paris (3600)
MySQL: 8.0.19-10 (Percona Server (GPL), Release '10', Revision 'f446c04') 
Database server time: 2020-06-08 16:26:26
Database server time offset: 0 s
Database server timezone: SYSTEM
Database session timezone: SYSTEM
Locale: fr_FR.UTF-8
Site / Admin language: fr / en
Web server: nginx/1.19.0
PHP server API: fpm-fcgi
RFC 2616 headers: 0
Server OS: Linux 5.4.0-33-generic
Admin-side theme: hive 4.8.1

My server:

Textpattern version: 4.9.0-dev (f5e70ae8fabc5a077d0c84ae2a578ea1)
Last update: 2020-05-31 13:50:37/2020-05-31 01:05:29
Textpattern path: __TXP-ROOT/textpattern
Article URL pattern: section_title
Production status: debug
Temporary directory path: __TXP-ROOT/textpattern/tmp
PHP version: 7.3.18-1+ubuntu16.04.1+deb.sury.org+1
GD Graphics Library: 2.3.0; Supported formats: GIF, JPEG, PNG, WebP.
Server timezone: Europe/London
Server local time: 2020-06-08 17:25:12
Daylight Saving Time enabled?: 0
Automatically adjust Daylight Saving Time setting?: 0
Time zone (GMT offset in seconds): Europe/Berlin (+7200)
MySQL: 5.6.47-87.0 (Percona Server (GPL), Release 87.0, Revision 9ad342b) 
Database server time: 2020-06-08 17:25:12
Database server time offset: 1 s
Database server timezone: SYSTEM
Database session timezone: SYSTEM
Locale: C
Site / Admin language: en / en
Web server: Apache/2.4.18 (Ubuntu)
Apache version: Apache/2.4.18 (Ubuntu)
PHP server API: apache2handler
RFC 2616 headers: 
Server OS: Linux 4.4.0-179-generic
Admin-side theme: hiveneutral 4.8.1

It’s not DST as I’ve tinkered with those and got the same output.
What’s Database server time offset: 1 s? The demo server reports 0 s.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#22 2020-06-08 16:42:35

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,767
GitHub

Re: strftime unix %s doesn't works on localhost

Bloke wrote #323652:

So is it an environment thing?

You’re on MySQL 5.6, demo server is 8.0 – I can spin up a fresh server minus MySQL for comparison, any good?

Offline

#23 2020-06-08 17:17:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

gaekwad wrote #323653:

You’re on MySQL 5.6, demo server is 8.0 – I can spin up a fresh server minus MySQL for comparison, any good?

Yeah, maybe, thank you. I just can’t figure why MySQL would even be a factor. In the tests, we’re calling a PHP function directly and it’s misbehaving. Now, sure, Txp might be getting in the way in an earlier part of the process so we’d have to eliminate that. That’s easy at the command line:

php -r "echo strftime('%s', '1591628404');"

If that returns -1, it’s PHP or the way it’s built (missing module, something? We’d have to compare a few phpinfo() stacks in various working and non-working environments). If not, it’s something else.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#24 2020-06-08 17:18:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

In fact, duh.Just tested that line on the demo server command line:

-1.

It’s PHP. So we need to start comparing environments. Where do we start?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#25 2020-06-08 17:21:12

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,767
GitHub

Re: strftime unix %s doesn't works on localhost

There are symlinks for PHP 7.3 and PHP 7.4, so try that again with:

php73 -r "echo strftime('%s', '1591628404');"
php74 -r "echo strftime('%s', '1591628404');"

Last edited by gaekwad (2020-06-08 17:22:04)

Offline

#26 2020-06-08 17:24:05

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

Both -1.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#27 2020-06-08 17:25:09

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,767
GitHub

Re: strftime unix %s doesn't works on localhost

Time to compare phpinfo()? I’m around for the evening, just waiting on stuff to compile.

Offline

#28 2020-06-08 17:26:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

gaekwad wrote #323658:

Time to compare phpinfo()? I’m around for the evening, just waiting on stuff to compile.

I’ll show you mine if you show me yours ;)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#29 2020-06-08 20:48:38

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: strftime unix %s doesn't works on localhost

Bloke wrote #323635:

Thanks for the report. In the meantime, this will get you the current article timstamp:

<txp:php>global $thisarticle; echo $thisarticle['posted'];</txp:php>...

Cool thanks, where can I find the full documentation about the $thisarticle and all the other cool friends please?

BTW if you already working on solving this, then it also the same in all other date related tags as:
<txp:posted />
<txp:expires />
<txp:image_date />
<txp:image_info />
<txp:file_download_created />

Offline

#30 2020-06-08 21:29:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,492
Website GitHub

Re: strftime unix %s doesn't works on localhost

Yeah, they all use our safe_strftime() function, which is basically a piggyback to PHP’s strftime() with the timezone/gmt offsets added to it. So any tag that uses any such time-based info will be affected.

Trying to zero in on the problem. We’ve ruled out a lot of things, but have yet to find the root cause.

btw, the easiest way to find out about the various $this strings is to import them from the global scope and just dmp(); them on your page, maybe in your default form. You can see how they react as you navigate around the front end.

These are the most fun ones, some of which are context dependent (so will return null unless you’re in a <txp:images> or <txp:file_download_list> or <txp:linklist> container, etc):

global $pretext,
    $thisarticle,
    $thissection,
    $thiscategory,
    $thispage,
    $thislink,
    $thisimage,
    $thisfile,
    $thisauthor;

dmp('TXP CONTEXT', $pretext);
dmp('CURRENT ARTICLE', $thisarticle);
dmp('CURRENT IMAGE', $thisimage);
dmp('CURRENT FILE', $thisfile);
dmp('CURRENT LINK', $thislink);
dmp('CURRENT SECTION', $thissection);
dmp('CURRENT URL CATEGORY', $thiscategory);
dmp('CURRENT URL AUTHOR', $thisauthor);
dmp('CURRENT URL PAGINATION', $thispage);

They’re probably documented somewhere, but if not, you’re right, they should be. I’ll check as we iterate the documentation for 4.8.

Last edited by Bloke (2020-06-08 21:41:46)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB