When i try to use php -f file.php
it says :
Uncaught Error: Call to undefined function gmp_init() in /file.php:10
However when I add the script as a function to my wordpress site, it doesn't give error and works. What can be the problem?
Using php7.1-fpm
If you have few versions of php and only one has GMP installed, you should run a command with php version.
php7.1 -f file.php