Page 1 of 1
pcntl and libphp4.so , Does it work ?
Posted: Tue Dec 09, 2003 6:42 pm
by hades123
Hello every body ,
I have compiled php with pcntl support. pcntl function works fine with the binary version of php. but when trying to work with it from under apache webserver. i got
Fatal error: Call to undefined function: pcntl_fork() in ....
i checked phpinfo it showed that php module was compiled with --enable-pcntl , but thats it no other module information. I am not sure if it should show other information or no !
Configure Command './configure' '--with-apxs=/opt/lams/servers/apache/bin/apxs' '--with-mysql=/opt/lams/servers/mysql/' '--with-gd' '--with-jpeg-dir=/usr' '--with-curl=/usr' '--with-zlib-dir=../zlib' '--enable-gd-native-ttf' '--with-config-file-path=/opt/lams/conf/php' '--with-xml' '--with-ttf' '--with-freetype-dir=../freetype-2.1.4' '--with-t1lib=../t1lib' '--with-png-dir=/usr/local' '--enable-pcntl'
I am runnign apache 1.3.29 with php 4.3.4 , on redhat ES 3
Thanks
Derek
Posted: Thu Dec 11, 2003 3:08 am
by Pyrite
Wait, if it works with the binary version of php, why do you need to compile it again?
I think you have to use php as a cgi module with Apache

Posted: Thu Dec 11, 2003 4:32 am
by hades123
i mean by binary version the command line php when i go :
php test-script.php
it works fine , and here is what i have inside the test script :
Code: Select all
<?php class Process
{
function go()
{
$handle = fopen ("/root/test.txt","w+");
for ( $i=1; $i<1000000; $i++ ) {
fwrite($handle,"WRITTING MANY LINES TO FILE\n");
}
fclose($handle);
}
}
$pid = pcntl_fork();
if ( !$pid)
$pid = pcntl_fork();
if ($pid) {echo "location: http://www.google.com"; exit();}
else {
$process = new Process();
$process->go();
die();
}
pcntl_waitpid($pid, &$status, 0);
?>
fromt he command line this test script will run fine, but if i try to do
http://www.mydomain.com/test-script.php
i get call to undefiened function pcntl_fork !!!
can you please explain how to compile php as a cgi-module.
Posted: Thu Dec 11, 2003 4:51 am
by Pyrite
It explains it in the php installation readme. You can compile it as an apache module or as a cgi module, and I think pcntl needs to be as an cgi module.
http://www.php.net/manual/en/install.commandline.php
Also, in the ./configure, might want to enable sockets and sigchild too.
Posted: Thu Dec 11, 2003 5:00 am
by Weirdan
PHP manual wrote:
LXXXIV. Process Control Functions
Introduction
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a webserver environment and unexpected results may happen if any Process Control functions are used within a webserver environment.
It means you can't use pcntl_* functions if php is compiled as apache module.
Posted: Thu Dec 11, 2003 5:03 am
by hades123
True,
but does that mean, it works , but its disabled somewhere??
i can't used CGI version !!!
they say "SHOULD NOT BE ENABLED" , this means its it can be used , or am i wrong ?
Posted: Thu Dec 11, 2003 5:05 am
by Weirdan
hades123 wrote:they say "SHOULD NOT BE ENABLED" , this means its it can be used , or am i wrong ?
It means "You can try but noone cares if it doesn't work"

Posted: Thu Dec 11, 2003 5:36 am
by Pyrite
The cgi way is a bit slower than the apache module way, and has some security concerns. But process control will work with php as a cgi module.
Posted: Thu Dec 11, 2003 5:37 am
by hades123
so i guess there is no way to enable this as an apache module.!!
Posted: Thu Dec 11, 2003 5:40 am
by Pyrite
Nope. Not according to php's manual anyways.
I know there are some 3rd party php builds for Windows that have this enabled. But that probably won't help you, since pcntl is really a Unix thing. And you could probably also call the script in question with the CLi php with a system() or exec() function to get the output, but that probably won't help you much either

Posted: Thu Dec 11, 2003 5:52 am
by hades123
Actually , i was thinking of doing this,
i will post back in this forum if this worked for me.
its a performance tradeoff, the script i am writting redirects user after sending some may be 15 MySQL update/insert/ read queries to the dataabase . i am trying to get the redirection done , without user waiting for the logging process to be finished. the script i posted above is the TEST situation. if system call will be less time to execute than to wait for logging to fiinish , i will do it.
Thanks to every body who tried to help here, if you guys have any ideas on a simpler way to do that , i will be glade to hear it

Posted: Thu Dec 11, 2003 5:55 am
by Pyrite
Thought I read an article on onlamp.com where that guy talked about a way to send a user someplace even when the script hasn't finished executing. Might look through the onlamp.com articles relating to MySQL tweaks or tips/practices.
Posted: Thu Dec 11, 2003 5:59 am
by hades123
Oh , that will be nice .. thanks for the tip .. do you vaguley remeer any keywords i can search for from this article
Posted: Thu Dec 11, 2003 6:16 am
by Pyrite