DICOM medical image processing: WEBPACS 3. PHP extension skeleton

Source: Internet
Author: User
DICOM medical image processing: WEBPACS 3. PHP extension skeleton background:

In the last two column blogs, we have explained how to build a web pacs environment. if the backend of the platform is not related to DICOM, there is actually nothing to do with PACS, so the last few articles seem to have some run-off questions, but don't worry. the establishment of the development environment itself is a huge and difficult project. the subsequent development of PACS will be as handy as the standalone version, after a while, we will soon begin to introduce the development of web pacs on the platform.

C/C ++:

The last two blog posts are just a clever attempt to the environment. The first blog directly uses the CGI provided by the APACHE service to directly call the exe file compiled by C, as the CGI technology has been gradually replaced by FastCGI, the first blog is used only for demonstration, not for later development. the second blog continues the first article, trying to transmit images, in the end, we cannot find the correct way to transmit image data in C language. we can only use PHP, Perl, and other explanatory languages to implement it, however, PHP and Perl cannot be well integrated with the DCMTK we introduced earlier, so the second blog does not play a major role. In view of the above reasons, it is decided to add a C/C ++ language PHP extension framework based on the FastCGI platform that has been built to realize the complete development environment of web pacs.

Preparations:

1) PHP source code: Download the PHP source code to generate the latest PHP runtime program that is the most compatible with the database, that is, php.exe (of course, you can also directly install Baidu/Google's latest PHP installation package by double-clicking );

2) PHP source code compilation: PHP source code is open-source and must be compiled in linux. Therefore, a mini Linux compiling environment must be installed in windows, download Cygwin or msys + MingGWen (for details about the differences, refer to the introduction in http://zengrong.net/post/1723.htm );?? Remember to modify $ cygwin_path = 'C: \ cygwin64 \ bin'syntax in ext_skel_win32.php after Cygwin (Linux compiler) is installed to indicate the location of sh.exe.

3) php sdk: the SDK is called Software Development Kit. as its name implies, it is a collection of commonly used gadgets (which can be understood as Apis) in Software Development. Here, we only use the php-binary-sdkpackage's bison.exeand flex.exe to copy it to the current windows directory ?? The purpose is to be able to find (or add the two paths to the environment variable Path ).

Compile and generate: PHP source code compilation:

The local computer is installed with VS2012 and VS2010. select VS2012 to compile the PHP source code. First, enter the command line status of VS, such:

Input: cd c: \ PHPDev \ php-5.6.2

Convert to the php source code directory, which contains the buildconf. bat file. (PHPDev is the upper-level directory created by myself. replace it with your local directory during actual Compilation)

Input: buildconfig. bat. start the script program buildconfig. js in the batch processing command and search all. w32 files in the directory to prepare for compiling in windows. If the task runs successfully, the system prompts "Now run 'configure -- help'". Otherwise, the system prompts "Error generating configure script, configure script was not copied ". After the compilation is successful, follow the prompts to enter configure -- help to view the compilation options. then, refer to the instructions in http://demon.tw/software/compile-php-on-windows.htmlin the blog post:

Configure? Without-xml? Without-wddx -- without-simplexml -- without-dom -- without-libxml -- disable-zlib -- without-pdo-sqlite? -Disable-odbc? -Disable-cgi -- enable-debug -- without-iconv -- disable-ipv6

Note:This is slightly different from the introduction in the blog post. before without, there are two "-". for details, refer to the prompt "configure -- help", for example:

After the configuration is complete, it is the compilation process. enter nmake to start the actual compilation.

[Note]: errors may occur during compilation, as shown in. in this case, use EditPlus, NotePad ++, and other editing tools to convert the file to UTF-8 encoding and restart nmake.

After compilation, The debug_tsfolder is displayed. The PHP executable file generated after the source code is compiled under the folder. the php.exe file is displayed in the figure showing the nmake compilation success result.

Input php.exe "echo 'hello world';" to the debug_tsdirectory. the correct output is displayed. This shows that the compilation of php source code on windows is successful.

PHP skeleton generation:

Php.exe ext_skel_win32.php -- extname = zsgetdcmimage

After obtaining the PHP executable program, the skeleton is generated. Go to the ext folder in the php source code, and you can see the two files used for skeleton generation, ext_skel and ext_skel_win32.php. Ext_skel, and then automatically changed the originally written C/C ++ dynamic library-based project to our own named project by using a php script. You can open the ext \ skeleton Directory of the source code and find that there is a project named skeleton. dsp, which is only named differently from the final skeleton project.

C Programming PHP extension test:

After the basic environment is set up, let's perform a practical test.

The skeleton project provides us with a test function with the same name as our project. for example, the function in my zsgetdcmimage project is:

/* Remove the following function when you have successfully modified config.m4   so that your module can be compiled into PHP, it exists only for testing   purposes. *//* Every user-visible function in PHP should document itself in the source *//* {{{ proto string confirm_zsgetdcmimage_compiled(string arg)   Return a string to confirm that the module is compiled in */PHP_FUNCTION(confirm_zsgetdcmimage_compiled){char *arg = NULL;int arg_len, len;char *strg;len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "zsgetdcmimage", arg);RETURN_STRINGL(strg, len, 0);}

The php source code we compiled above enables the debugging status, that is, the parameter is -- enable-debug. Therefore, the corresponding Debug_TS mode should be used for compiling the skeleton program, at the same time, the link Library php5ts_debug.lib is added. the file is in the Debug_TS source code folder compiled by php.


After compilation is successful, the generated zsgetdcmimage. the dll is copied to the ext subdirectory in Debug_TS, the Directory of the compiled php executable program, and php in Debug_TS is modified. ini, add extension = ext/zsgetdcmimage. dll statement.

Finally, create a test. php document. the code is as follows:

 

In the command line status, go to the debug_tsdirectory and enter php.exe test. php. if the configuration is successful, the following output is displayed:


Now, the skeleton extension and instance test are complete.

Note: change PHP in WampServer

In the first two blog posts, we have used wamp to fight for an opportunity to use the Apache + PHP + MySQL Web service framework to compile the above-compiled zsgetdcmimage. dll extensions are placed in c: \ wamp \ bin \ php5.5.12 \ ext. after wampServer is started, the following error message cannot be called:

This error indicates that the extension generated by the extension skeleton of php5.6.2 does not match in php5.5.12. In this case, to add the PHP extension skeleton to the previously established web pacs platform, there are only two options: 1) Download the source code of the corresponding version php5.5.12, rebuild the skeleton program according to the above record; 2) replace php in the wamp installation package.

I was not very familiar with WampServer configurations, so I would like to take advantage of this opportunity to learn it easily. Then I decided to replace PHP in the WampServer installation package with php5.5.12 and php5.6.2. I searched the internet and found a lot of related information. The basic operation ideas mainly refer to the introduction of the two blog posts. Now I am given in Win7 32 bit + WampServer-64-bits-php-5-5 environment under the specific implementation steps. First, go to the c: \ wamp \ bin \ php directory, and decompress the latest binary installation package in windows downloaded from the php official website to this directory. for example, the complete path of php5.6.2 is c: \ wamp \ bin \ php \ php5.6.2. the subsequent modification method and sequence are as follows:

WampServer modification 1 Wampmanager. conf

Replace the [php] tag with the new version 5.6.2.

Replace the version number in the [phpCli] label with 5.6.2.

WampServer modification 2 Wampmanager. ini

Use NotePad ++ or EditPlus and other text editors to search for phpX. X. X in a file and replace it with php5.6.2;

[Note]: replace X. X. X with 5.6.2, for example, the Caption under [switchPhp5.6.2] and [phpVersion.

PHP modification 1 Php. ini 1. set extension_dirto the path of php.exe in the new version. extension_dir = "c: \ wamp \ bin \ php \ php5.6.2 \ ext \"
2) then selectively cancel the annotation of extension = XXX. dll and add php extensions.
PHP modification 2 PhpForApache. ini Copy the php. ini file and rename it phpForApache. ini.
APACEH modification Httpd. conf

In the FastCGI configuration moduleVersion numberModify the settings as follows:

LoadModule php5_module "c:/wamp/bin/php/php5.6.2/php5apache2_4.dll"

PHPIniDir c:/wamp/bin/php/php5.6.2

LoadModule fcgid_module modules/mod_fcgid.so

AddHandler fcgid-script. fcgi. php

# Directory for storing php. ini

FcgidInitialEnv PHPRC "c:/wamp/bin/php/php5.6.2"

# Set PHP_FCGI_MAX_REQUESTS to be greater than or equal to FcgidMaxRequestsPerProcess to prevent the php-cgi process from exiting before processing all requests

FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

# Php-cgi maximum number of requests for each process

FcgidMaxRequestsPerProcess 1000

# Maximum number of php-cgi processes

FcgidMaxProcesses 5

# Maximum execution time

FcgidIOTimeout 120

FcgidIdleTimeout 120

# Php-cgi path

FcgidWrapper "c:/wamp/bin/php/php5.6.2/php-cgi.exe". php

AddType application/x-httpd-php. php

Actual test

1) put the zsgetdcmimage. dll extension compiled using the PHP skeleton to the php5.6.2 \ ext directory.

2) create a php test file in the wamp \ www Directory, test. php

Enter localhost \ test. php in the browser

The output is as follows:

So far, the change of the PHP version in the WampServer installation package has been successfully completed. after several attempts, we have successfully built the basic environment for web pacs development with three blog posts. In the future, we will introduce how to use the PHP extension skeleton and DCMTK to implement various web pacs functions.

Follow-up blog posts:

Use PHP Skel and DCMTK to develop web pacs applications

Use DCMTK to build a WML server

Using oracle to directly operate DICOM data

Application of C # asynchronous programming mode in fo-dicom

Test the three network connection modes of VMWare

Author:Zssure@163.com

Time: 2014-10-31

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.