Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Call to undefined function cal_days_in_month() #317

Closed
csageder opened this issue Dec 7, 2021 · 14 comments
Closed

Call to undefined function cal_days_in_month() #317

csageder opened this issue Dec 7, 2021 · 14 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@csageder
Copy link

csageder commented Dec 7, 2021

Describe the bug
I have installed the newest version of the Controlling Plugin. This Plugin uses the php function cal_days_in_month().

To Reproduce
Steps to reproduce the behaviour:

  1. Start the container
  2. Execute a shell within the container
  3. Within the shell run php -a
  4. Run echo cal_days_in_month(CAL_GREGORIAN, 8, 2003);
  5. The result is the following error message:
PHP Warning:  Uncaught Error: Call to undefined function cal_days_in_month() in php shell code:1
Stack trace:
#0 {main}
  thrown in php shell code on line 1

Desktop (please complete the following information):

  • OS: CentOS 7
  • Docker version: 1.13.1
  • Docker compose version: n/a - Kubernetics / OKD 3.11

Command used to run the container

  • System runs within an OKD 3.11 Cluster
  • Image: kimai/kimai2:apache-1.16.5-prod

Additional context
Function should work for php 4.1+ onwards: https://www.w3schools.com/php/func_cal_cal_days_in_month.asp

@tobybatch
Copy link
Owner

So it seems that PHP needs to be built with calendar support enabled.

https://stackoverflow.com/questions/49612838/call-to-undefined-function-cal-days-in-month-error-while-running-from-server

I try to avoid adding too many extensions to support third party plugins. Once I start every plugin author wants a slightly different PHP set up. :)

However... Adding calendar support to a time tracking app seems justified. I'll add it to the todo list, it's not a massive change. I'll try and get it done soon-ish.

@tobybatch tobybatch self-assigned this Dec 7, 2021
@tobybatch tobybatch added the enhancement New feature or request label Dec 7, 2021
@kevinpapst
Copy link
Collaborator

Yeah or the method is replaced by a one line solution from php.net:
https://www.php.net/manual/de/function.cal-days-in-month.php#38666

function days_in_month($month, $year) { 
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); 
} 

@tobybatch I never needed any of those method in over 10 years of development around Kimai...

I checked a couple of systems, they all have calendar compiled in, so it is not a very exotic extension. BUT: Kimai composer does not require it. And it is not mentioned in the Store page.

Not saying that you should not add that extension, but blindly requiring new PHP extensions in a paid extension and then relying on the community to fix that problem is not "best practice". I emailed the author.

@tobybatch
Copy link
Owner

@kevinpapst Yeah, I saw that too. It's being used by the Controlling Plugin. We don't build PHP for the container. If it's an option form the underlying mages then it's trivial to add, else out of scope. In that case it's a feature request for the plugin.

I'll look when I get time.

@j0hannesr0th
Copy link

Hi @tobybatch I'm the creator of the Controlling Plugin. How are we going to resolve this?

Red pill: I'll test the suggest function of Kevin or find an other solution
Blue pill: You add support for the calendar functions of PHP

Hope you are a Matrix fan, too and get the reference 😉

@csageder
Copy link
Author

csageder commented Dec 7, 2021

@tobybatch Adding the extension seam to be straight forward.
If I understand the strategy right a new extension image is created, and then only the resulting files are copied to the base image

# php extension calendar
FROM ${BASE}-php-ext-base AS php-ext-cal
RUN docker-php-ext-install -j$(nproc) calendar

And adding in the base image

# PHP extension calendar
COPY --from=php-ext-cal /usr/local/etc/php/conf.d/docker-php-ext-???.ini /usr/local/etc/php/conf.d/docker-php-ext-???.ini
COPY --from=php-ext-cal /usr/local/lib/php/extensions/no-debug-non-zts-20200930/???.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/???.so

Is this right?

@tobybatch
Copy link
Owner

@csageder Yes that's totally right. I just wonder if the better solution isn't to remove the dependency on a custom php compilation in the plugin, using Kevin's solution.

I don't mean to be an arse, but each extension has some size to it:

www-data@86b05252f145:/usr/local/lib/php/extensions/no-debug-non-zts-20200930$ ls -lah
total 4.2M
drwxr-xr-x 1 root root 4.0K Oct 25 09:26 .
drwxr-xr-x 1 root root 4.0K Sep  3 18:28 ..
-rwxr-xr-x 1 root root 432K Oct 25 09:26 gd.so
-rwxr-xr-x 1 root root 2.0M Oct 25 09:26 intl.so
-rwxr-xr-x 1 root root 107K Oct 25 09:26 ldap.so
-rwxr-xr-x 1 root root 1.4M Sep  3 18:28 opcache.so
-rwxr-xr-x 1 root root  41K Oct 25 09:25 pdo_mysql.so
-rwxr-xr-x 1 root root 114K Sep  3 18:28 sodium.so
-rwxr-xr-x 1 root root  45K Oct 25 09:25 xsl.so
-rwxr-xr-x 1 root root  98K Oct 25 09:25 zip.so

and in if I build this one in then the next extension that need a custom build wants that one built in too and I may just as well build all ~60 of the extensions into the image.

Let me check with the other repo maintainers.

@tobybatch
Copy link
Owner

You could extend our image if you need a custome ext.

Something like

# apache debian php extension base
FROM php:8.0.10-apache-buster AS apache-php-ext-base
RUN apt-get update
RUN apt-get install -y \
        libldap2-dev \ 
        libicu-dev \ 
        libpng-dev \ 
        libzip-dev \ 
        libxslt1-dev \
        libfreetype6-dev
        
# php extension calendar
FROM apache-php-ext-base AS php-ext-cal
RUN docker-php-ext-install -j$(nproc) calendar

# PHP extension calendar
FROM kimai/kimai2:apache
COPY --from=php-ext-cal /usr/local/etc/php/conf.d/docker-php-ext-???.ini /usr/local/etc/php/conf.d/docker-php-ext-???.ini
COPY --from=php-ext-cal /usr/local/lib/php/extensions/no-debug-non-zts-20200930/???.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/???.so

This isn't tested but should work.

@tobybatch
Copy link
Owner

@Schrolli91 @jokay Opinions please?

root@889cddf916e0:/var/www/html# ls -lah /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
...
-rwxr-xr-x 1 root root  41K Dec  8 09:20 calendar.so
...

Pro:

  • It's only 41k
  • A plugin requires it

Con:

  • Does it set a president for add other php extensions (there are ~60)
  • It's not a core requirement for kimai
  • There is a work around.

@Schrolli91
Copy link
Collaborator

Schrolli91 commented Dec 8, 2021

Users with special needs should create their own images - they can use this repo as base.
Otherwise we have to ship the image with ALL possible extension.

IMHO

@jokay
Copy link
Collaborator

jokay commented Dec 8, 2021

@tobybatch I'm sorry but I have very limited time and can't support the Docker image developmenet for kimai2 anymore.

For this case, I would say the same as @Schrolli91.

  • Keep it as it is as long as it's not required by kimai2 (only install extensions required by kimai2)

or

  • Provide an image with all required extensions for all possible plugins (difficult to maintain)

@Schrolli91
Copy link
Collaborator

@tobybatch
Maybe we can add a section in the docs - "how to build a custom image" - like your proposal above.

@stale
Copy link

stale bot commented Jan 10, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 10, 2022
@dhoernel
Copy link

The problem persists with the latest stable release:
Kimai version 1.30.11
Controlling plugin version 1.23

Is there any step by step guide to resolve it or (better) a Docker image that fixes the problem?

@tobybatch
Copy link
Owner

Can you open a new ticket please with all the relevant info, docker command, files, logs etc. This is a closed issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

7 participants