PHP sem_get() does not work - php

I am trying to use semaphores on php but cannot get sem_get() function to work. Here is my PHP code:
<?php
$key = 123567;
$maxAcquire = 1;
$permissions = 0666;
$autoRelease = 1;
//it gives the error on the line below
$semaphore = sem_get($key, $maxAcquire, $permissions, $autoRelease);
sem_acquire($semaphore);
echo "hello world!";
sem_release($semaphore);
?>
When I try to run it with:
php semaphore.php
It prints this error:
PHP Fatal error: Uncaught Error: Call to undefined function sem_get()
in /root/semaphore.php:8
Stack trace:
#0 {main}
thrown in /root/semaphore.php on line 8
I am working on Arch Linux with PHP 7.0.3 (cli). I guess the solution is so simple but I couldn't find a way to fix it. If you could help me, I would appreciate it. Thanks.

Support for semaphores is not a standard feature of php.
It has to be activated via compiler --enable-sysvsem option when creating the php binary.
See explanation in manual: http://php.net/manual/en/sem.installation.php

Thank you all! I uncommented the line :
extension=sysvsem.so
on php.ini and it worked!

The semaphore extension is not available by default, as stated in the docs:
Support for this functions are not enabled by default. To enable System V semaphore support compile PHP with the option --enable-sysvsem . To enable the System V shared memory support compile PHP with the option --enable-sysvshm . To enable the System V messages support compile PHP with the option --enable-sysvmsg .
If you are on a hosted server, then that hosting service probably does not offer this.

Have a look at the docs. It feels like you do not have installed php with semaphores properly. Have a look at the installation instructions.

Related

Uncaught Error: Call to undefined function odbc_connect() [duplicate]

I'm testing out php 7 and have come across this error:
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
From the doc page: http://php.net/manual/en/function.odbc-connect.php php 7 is not listed as supported.
Does anyone have a way around this or know when it will be supported?
Thanks#
There is written in doc: ODBC support doesn't need any extension dll. It is true in PHP 5.x, I had to remove "extension=php_odbc.dll" from ini file.
But in PHP 7 I had to put it back.
I found the file "ext/php_odbc.dll" in the new PHP 7 directory again. It works for me :).
The DOC page does list PHP 7, so just install php-odbc and you should be good to go. Currently using it myself on RedHat EL7 with Remi php7.
I ran into the same problem. However according to the link you provided PHP7 is in fact supported. So I'm not sure why you have so many comments telling you to go re-write your code.
This is what ultimately fixed the issue for me:
sudo apt-get install php-odbc
Followed by restarting Apache.
PHP 7.2.7, add extension=php_odbc.dll in php.ini file while either using database as MS Access or Sql Server
C:\xxxxxx\php\php.ini
*no semicolon before to extension=php_odbc.dll
Just enble "php_odbc.dll" extension by removing the semicolon and restart Apache.
If there is no such line in php.ini, simply create it on yourself (you will find many similar lines in php.ini) by adding: extension=php_odbc.dll and then restart Apache.
If Apache does not start or cannot load php_odbc.dll, look into to the ext-Folder of PHP, if there is such a DLL called php_odbc.dll. If there is no such DLL, Xampp/PHP7 does not support ODBC natively. In that case you should install an older Xampp Version with PHP 5.x
From php.ini file:
> ; Notes for Windows environments :
> ;
> ; - ODBC support is built in, so no dll is needed for it.
> ; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
But, in PHP 7, ODBC is not by default. Explicit
extension=odbc
worked for me (new syntax recommended)
Edit:
If your architecture is x64
you must use C:\Windows\SysWOW64\odbcad32.exe
instead of C:\Windows\system32\odbcad32.exe
Here is the error message:
Redhat PHP Fatal error: Uncaught Error: Call to undefined function
odbc_connect()
On Redhat Linux 7 you run:
yum install php-odbc
You will get these packages marked in red:
Code sample to test your connection via php command line run: php [filename].php
<?php
// filename: test-connection.php by running command -> php test-connection.php
$connect = odbc_connect("Driver=FreeTDS; Server=sbase.company.ca; Port=1433; TDS_Version=8; ClientCharset=UTF-8; Database=mydbase",'company\\user', 'password');
$query = "SELECT * from mytable";
// perform the query
$result = odbc_exec($connect, $query);
// fetch the data from the database
while(odbc_fetch_row($result)){
$suid = odbc_result($result, 1);
$uid = odbc_result($result, 2);
$gid = odbc_result($result, 3);
$name = odbc_result($result, 4);
print("$name|$suid|$uid|$gid\n");
}
// close the connection
odbc_close($connect);
?>
Enjoy!

Call to undefined function odbc_connect() php 7

I'm testing out php 7 and have come across this error:
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
From the doc page: http://php.net/manual/en/function.odbc-connect.php php 7 is not listed as supported.
Does anyone have a way around this or know when it will be supported?
Thanks#
There is written in doc: ODBC support doesn't need any extension dll. It is true in PHP 5.x, I had to remove "extension=php_odbc.dll" from ini file.
But in PHP 7 I had to put it back.
I found the file "ext/php_odbc.dll" in the new PHP 7 directory again. It works for me :).
The DOC page does list PHP 7, so just install php-odbc and you should be good to go. Currently using it myself on RedHat EL7 with Remi php7.
I ran into the same problem. However according to the link you provided PHP7 is in fact supported. So I'm not sure why you have so many comments telling you to go re-write your code.
This is what ultimately fixed the issue for me:
sudo apt-get install php-odbc
Followed by restarting Apache.
PHP 7.2.7, add extension=php_odbc.dll in php.ini file while either using database as MS Access or Sql Server
C:\xxxxxx\php\php.ini
*no semicolon before to extension=php_odbc.dll
Just enble "php_odbc.dll" extension by removing the semicolon and restart Apache.
If there is no such line in php.ini, simply create it on yourself (you will find many similar lines in php.ini) by adding: extension=php_odbc.dll and then restart Apache.
If Apache does not start or cannot load php_odbc.dll, look into to the ext-Folder of PHP, if there is such a DLL called php_odbc.dll. If there is no such DLL, Xampp/PHP7 does not support ODBC natively. In that case you should install an older Xampp Version with PHP 5.x
From php.ini file:
> ; Notes for Windows environments :
> ;
> ; - ODBC support is built in, so no dll is needed for it.
> ; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
But, in PHP 7, ODBC is not by default. Explicit
extension=odbc
worked for me (new syntax recommended)
Edit:
If your architecture is x64
you must use C:\Windows\SysWOW64\odbcad32.exe
instead of C:\Windows\system32\odbcad32.exe
Here is the error message:
Redhat PHP Fatal error: Uncaught Error: Call to undefined function
odbc_connect()
On Redhat Linux 7 you run:
yum install php-odbc
You will get these packages marked in red:
Code sample to test your connection via php command line run: php [filename].php
<?php
// filename: test-connection.php by running command -> php test-connection.php
$connect = odbc_connect("Driver=FreeTDS; Server=sbase.company.ca; Port=1433; TDS_Version=8; ClientCharset=UTF-8; Database=mydbase",'company\\user', 'password');
$query = "SELECT * from mytable";
// perform the query
$result = odbc_exec($connect, $query);
// fetch the data from the database
while(odbc_fetch_row($result)){
$suid = odbc_result($result, 1);
$uid = odbc_result($result, 2);
$gid = odbc_result($result, 3);
$name = odbc_result($result, 4);
print("$name|$suid|$uid|$gid\n");
}
// close the connection
odbc_close($connect);
?>
Enjoy!

The Intl Component Symfony2

I am deploying a symfony2 application to a server where php intl extension is not enabled. I have no say in this.
The answer to this question suggests a solution:
Possible to disable intl requirement for Symfony?
I have put the "symfony/intl": "3.0.*#dev" in my composer.json and everything updates fine. Must I do anything more to activate/enable it? In AppKernel like with bundles?
Now I get the following errors when I run check.php on deployment server:
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Extension intl does not exist' in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php:658
Stack trace:
#0 /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php(658): ReflectionExtension->__construct('intl')
#1 /web/folk/eirik/030476/releases/20150528181203/app/check.php(6): SymfonyRequirements->__construct()
#2 {main}
thrown in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php on line 658
I look at line 658 in SymfonyRequirements.php and find:
if (class_exists('Locale')) {
if (defined('INTL_ICU_VERSION')) {
$version = INTL_ICU_VERSION;
} else {
$reflector = new ReflectionExtension('intl');
ob_start();
$reflector->info();
$output = strip_tags(ob_get_clean());
preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
$version = $matches[1];
}
$this->addRecommendation(
version_compare($version, '4.0', '>='),
'intl ICU version should be at least 4+',
'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
);
}
I don't know much about this stuff, but I assume
new ReflectionExtension('intl') requires the intl exension to be enabled in php, which is no option for me.
But what is INTL_ICU_VERSION? And why is it not defined? And why won't the symfony/intl component fix this for me?
And btw
if (class_exists('Collator')) {
$this->addRecommendation(
null !== new Collator('FR_fr'),
'intl extension should be correctly configured',
'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'
);
}
I have also changed 'FR_fr' to 'en' here, this was an error given by check.php that disappeared when I made the change.
If you take a look into the file check.php you are running you'll see that it does not load the Composer autoloader therefore it makes no difference whether you have installed that Symfony Intl component or not, it'll keep failing because it's looking for a required extension that is not there. The SO question you linked does mention the problem got solved but it doesn't say that the check passed.
If that extension was your problem with your Symfony installation and the only locale you needed is "en" than the problem should have gone away already after you installed the Symfony Intl drop in replacement. Although if you want to run the check for other problems you can comment out those lines so the script can finish. Don't worry that script is totally decoupled from the framework, you can even delete it when you are done.
If you are using Capistrano for the deployment and you are running those checks on every deployment you might want to disable that as well, or customise that script for your needs.

Few function of ladybug debugger not working in symfony2 php app

I am using this
https://github.com/raulfraile/LadybugBundle
They have three functions
ld($var1[, $var2[, ...]]): shortcut for ladybug_dump
ldd($var1[, $var2[, ...]]): shortcut for ladybug_dump_die
ldr($format, $var1[, $var2[, ...]]): shortcut for ladybug_return
First two are working but for third it says undefined function
Also i tried this to dump json then i also get error
ld(json_decode($jsonContent, true));
and i get this
UndefinedFunctionException: Attempted to call function "bccomp" from
namespace "Ladybug\Type" in
/var/www/html/site/Symfony/vendor/raulfraile/ladybug/src/Ladybug/Type/FloatType.php
line 115
The bccomp() function needs the php BC Math extension.
These functions are only available if PHP was configured with
--enable-bcmath .
The Windows version of PHP has built-in support for this extension
Check php -i | grep -i bcmath ...
There should be a line ...
BCMath support => enabled
... if the extension is enabled. Otherwise you'll probably need to recompile php with --enable-bcmath.

Runkit : does not work on a linux server

I have a problem with PECL::Runkit with this little example
index.php contain <?php
runkit_import('a.php');
runkit_import('b.php');
Doublon::get();
a.php et b.php each contain the same code
class Doublon
{
static function get() { echo "class " . __FILE__; }
}
On my PC (Windows XP, Wampserver 2, php 5.2.9-2, runkit DLL bundled with
Wamp) it work and index.php show
class C:\wamp2\www\utilitaires\essais\runkit\b.php
On my Linux CentOS 5 server, PHP 5.2.10, Runkit compiled by hand
Warning: runkit_import() [function.runkit-import]: class doublon not
found in /shares/public/cedric/test/index.php on line 2
Warning: runkit_import() [function.runkit-import]: Cannot redeclare
class doublon in /shares/public/cedric/test/index.php on line 2
Warning: runkit_import() [function.runkit-import]: class doublon not
found in /shares/public/cedric/test/index.php on line 3
Warning: runkit_import() [function.runkit-import]: Cannot redeclare
class doublon in /shares/public/cedric/test/index.php on line 3
Fatal error: Class 'Doublon' not found in
/shares/public/cedric/test/index.php on line 4
One problem : runkit's make test give me 100% of tests failed, but I still don't know why.
The runkit version from the linux distribution just make crash Apache :
PHP Startup: Timezone database is corrupt
I dropped xdebug, return to php 5.2.9, but the errors are the same
Thanks in advance, Cédric
The Package site says:
WARNING: 0.9 does not compile with PHP 5.2+ so use the CVS version instead.
Are you using the CVS version?
The up-to-date runkit extension can be found on http://github.com/zenovich/runkit
Anyway, as I know, runkit never had a feature to define new class on importing. It only can add or change members of existing classes. If you really want this, you can open the feature-request on http://github.com/zenovich/runkit
To determine why you get different results on your platforms, I need to know the versions of runkit and PHP for both of them. You can get all the information using the command 'php -i'.

Categories