7

I am using Windows 7, php 5.3.5 and WAMP server. I have two php files: trigger.php and background.php.
I want to run background.php as a background process. I have to call this file from trigger.php. To accomplish this I used below method. I included following code in trigger.php to make background.php to process in background.

$handle = popen('start /b C:\wamp\bin\php\php5.3.5\php.exe     C:\wamp\www\email3.php','r');

in background.php I have the follwing code to connect to database.

$conn_string = "host=localhost port=5432 dbname=tagbase user=postgres password=postgres";  

now, on parsing this line am getting the follwing error :

Fatal error: Call to undefined function pg_connect() in C:\wamp\www\background.php on line 3 Call Stack: 0.0002 322792 1. {main}() C:\wamp\www\background.php:0

By searching in in the internet I found some solutions, and made changes as recommended below in php.ini,

uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",

also I do have php_pdo_pgsql.dll and php_pgsql.dll files in c:/wamp/bin/php/php5.3.5/ext/ folder.

Any suggestions are appreciated.

Spontifixus
  • 6,570
  • 9
  • 45
  • 63
Shashidhar Gr
  • 420
  • 2
  • 6
  • 15

3 Answers3

25

Apache 2.2.X configuration

Add the next line to the Apache 2.2.x httpd.conf configuration:

LoadFile "C:/Program Files/PostgreSQL/{version}/bin/libpq.dll"

Above line must be entered before the next line.

LoadModule php5_module "c:/wamp/bin/php/php5.2.11/php5apache2_2.dll"

PHP 5.2.X Configuration

Enable the following two lines in the php.ini configuration file. By 'Enable' i mean, remove trailing ; (semicolon). By these, you un-comment the line.

extension=php_pdo_pgsql.dll
extension=php_pgsql.dll

Restart WAMP

Test by adding this in your index.php

echo extension_loaded('pgsql') ? 'yes':'no';

(source: http://www.plaatsoft.nl/wamp-postgresql-integration/)

Jordi Kroon
  • 2,607
  • 3
  • 31
  • 55
  • hi Mr.jordi kroon, as you suggested when i included the following in httpd.conf file : lineLoadFile “C:/Program Files/PostgreSQL/9.1/bin/libpq.dll”, my server itself is not restarting properly. And LoadModule php5_module “c:/wamp/bin/php/php5.3.5/php5apache2_2.dll” already present in that configuration file. – Shashidhar Gr Feb 13 '13 at 08:48
  • The load file.. should point to the libpq.dll. Check the path. – Jordi Kroon Feb 13 '13 at 09:04
  • i checked. path is correct. LoadFile "C:/Program Files/PostgreSQL/9.1/bin/libpq.dll",since in the path "Program Files" contains space ,am i suppose to escape that space.? – Shashidhar Gr Feb 13 '13 at 09:17
  • No, since there are quotes arround them. Check your apache error logs. – Jordi Kroon Feb 13 '13 at 09:18
  • apache error logs also contains same error:PHP Fatal error: Call to undefined function pg_connect() in C:\wamp\www\background.php on line 3 PHP Stack trace: PHP 1. {main}() C:\wamp\www\background.php:0 [Wed Feb 13 14:50:53 2013] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/favicon.ico – Shashidhar Gr Feb 13 '13 at 09:27
  • This did it for me, thanks. Some users may need to beware of the quotes Jordi has used in his answer; use these: " " – Vael Victus Oct 11 '13 at 16:05
  • Thanks, quotes changed. – Jordi Kroon Oct 13 '13 at 18:21
  • Just so that anyone else reading this doesn't mess up: on Windows you need forward slashes to make it work, so : LoadFile "C:\Program Files\PostgreSQL\{version}\bin\libpq.dll" – Milos Mar 14 '15 at 05:38
4

if we install WAMP server, we will get two php.ini files. one in C:\wamp\bin\php\php5.3.5 and another in C:\wamp\bin\apache\Apache2.2.17\bin.

if we execute a php file from browser, then php.ini file in C:\wamp\bin\apache\Apache2.2.17\bin will be referred. if we execute a php file from command line, then php.ini file in C:\wamp\bin\php\php5.3.5 will be referred.

what ever the changes i made enable/disable the dll in PHP->PHP extensions,all the changes will be saved in C:\wamp\bin\apache\Apache2.2.17\bin\php.ini file. but C:\wamp\bin\php\php5.3.5\php.ini file remains unchanged.

for my problem, i made the following changes

uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",

in C:\wamp\bin\php\php5.3.5\php.ini file. Now its working good. :)

Shashidhar Gr
  • 420
  • 2
  • 6
  • 15
0

In my case with Apache/2.4.10 PHP Version 5.4.32 PostgeSQL 9.3 I added libpq.dll into Apache httpd.conf from PHP catalog because Apache refused to start with libpq.dll from PostgreSQL 9.3

Jeff_Alieffson
  • 2,672
  • 29
  • 34