I have a stored procedure on MS SQL 2008, that runs perfect if called from SSMS. It takes data from a view that is based on a table from linked server and updates local table with this data. So right now during testing it inserts 500 rows and it takes about 13 seconds and SSMS grows up to take about 500 MB RAM (although most of this time and memory is probably used to output this data on the screen).
However if I run a php script that executes this procedure, it only takes 2 or 3 seconds and it only inserts 94 rows.
I was playing with my php.ini, but still no results. Here are the settings that I've updated.
max_execution_time = 600
max_input_time = 600
memory_limit = 512M
Here is my code
ALTER PROCEDURE [dbo].[Update_emp]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @emp_no varchar(10),@emp_name varchar(100),@emp_short_name varchar(100),@emp_position varchar(100),@quit_date date
,@dept_id int;
--update c_emp_t table with current data from 1C server
DELETE dbo.c_emp_t;
INSERT INTO dbo.c_emp_t
SELECT *
FROM dbo.c_emp_v;
DECLARE emp_cursor CURSOR FOR
SELECT emp_no,emp_name,emp_short_name,emp_position,dept_id,quit_date FROM dbo.c_emp_t ORDER BY emp_no, quit_date;
--read emp data
OPEN emp_cursor
FETCH NEXT FROM emp_cursor INTO @emp_no,@emp_name,@emp_short_name,@emp_position,@dept_id,@quit_date
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT emp_no FROM dbo.emp_t WHERE emp_no = @emp_no;
IF @@ROWCOUNT>0
BEGIN
UPDATE dbo.emp_t SET emp_name = @emp_name, emp_short_name = @emp_short_name, emp_position = @emp_position, dept_id = @dept_id, quit_date = @quit_date WHERE emp_no = @emp_no;
END;
ELSE
BEGIN
INSERT INTO dbo.emp_t VALUES(@emp_no,@emp_name,@emp_short_name,@emp_position,'TPV',@dept_id,@quit_date);
END;
FETCH NEXT FROM emp_cursor INTO @emp_no,@emp_name,@emp_short_name,@emp_position,@dept_id,@quit_date
END
CLOSE emp_cursor
DEALLOCATE emp_cursor
END
And this is my php call to this procedure
if(!empty($_REQUEST['import_from_1c']))
{
// $sql="{ call dbo.Update_dept }";
// $stmt = sqlsrv_query( $conn, $sql );
// if( $stmt == false)
// die( print_r( sqlsrv_errors(), true) );
// sqlsrv_free_stmt( $stmt);
$sql="{ call dbo.Update_emp }";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt == false)
die( print_r( sqlsrv_errors(), true) );
else
echo "Success</br>";
sqlsrv_free_stmt( $stmt);
}
As you can see I commented a call to one stored procedure - it pretty much is the same idea, but it has only about 60 rows and it works both in SSMS and PHP.
I am using PHP version 5.3.27 TS VC9 on IIS.
Any idea why it happens or what can I do to figure out the root of this issue?