473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

C Code and PHP

14
I already asked in the javascript forum
step by step instructions how to write a code that is going to
use some simple C function and show it in the server.

see the following link

http://bytes.com/topic/javascript/answers/876590-how-do-i-write-code-javascript-use-function-c

I have visual C++ 2008 and microsoft visual studio 2008
I hope that you can help me to give me step by step instructions how to write code that simply show how to write code that does the same as my javascript code does that mean showing the result of plus1(5) in the server by calling the simple C function that I have.

Thanks in advance,
Uri
Nov 8 '09 #1
10 4185
Dormilich
8,658 Expert Mod 8TB
you may want to try SWIG.

you can also make a PECL extension.

and if the C function is simple, it’s better to write it in PHP (so you don’t have the interface overhead)
Nov 8 '09 #2
Markus
6,050 Expert 4TB
SWIG article (not published).

Or if you want to write the PHP extension yourself (it's not so hard), see this link on extension development for PHP on Windows.

Mark.
Nov 8 '09 #3
Dheeraj Joshi
1,123 Expert 1GB
Yeah... You can use SWIG... Its easy to use.

As MARK told you can create your own PHP extensions also... Both will serve your purpose.

Regards
Dheeraj Joshi
Nov 9 '09 #4
urib
14
I do not understand how I write the C code in the example
of
SWIG -- Easy way of communication between C and PHP

Here are my comments:
comment 1:
I know to write a new code in C in visual C++ 2008 by the following steps:

1)file->new project
when I select empty project and select a name for the project(I chose example

2)add new files to the project
project->add new item when I can choose between .cpp file and .h file(when practically .cpp include also .c if I save the file as .c)

Comment 2:
I am not sure what to do about adding .i files to project.

When I add a new file to the project I need to choose between code and UI and property sheet.
My experience is only with choosing code and in this case I simply choose between source file and header file).

Comment 3:
I do not understand the following:
to compile use the following commands
swig -php MyModule.i
gcc -c -o MyModule.c
gcc `php-config --includes` -fpic -c MyModule_wrap.c
gcc -shared MyModule.o MyModule_wrap.o -o MyModule.


I will be happy if you give me step by step instructions how to do it.
My experience is that I simply compile by build solution command from visual C++ 2008 to compile projects in C.

Uri
Nov 9 '09 #5
Dormilich
8,658 Expert Mod 8TB
@urib
these are CLI* commands. swig is the command to start the SWIG programme, gcc (GNU Compiler Collection) is a widespread C-compiler.

* Command Line Interface, in *NIX systems often called Terminal or Shell, in windows it would be the Command Prompt.
Nov 9 '09 #6
Dheeraj Joshi
1,123 Expert 1GB
SWIG has support for Windows too... Download the latest stable SWIG executable and start coding...

Regards
Dheeraj Joshi
Nov 9 '09 #7
urib
14
I download SWIG for windows from the download in the following page

http://www.swig.org/index.php

I guess that swigwin-1.3.40 is the right file.

Unfortunately I have no idea how to continue when my target is only to show the result of a simple function in C on the server.

I see no step by step instructions and the instructions that I got in a different page also did not help.

The different page is
http://wiki.php.net/internals/windows/stepbystepbuild

I could do steps 1,2 in the Quick 'n' dirty part but did not understand how to do step 3 and I am also not sure if I did steps 7-10 correctly(I chose with the mouse start->programs->microsoft windows SDK v6.1->cmd shell and got some window with the name microsoft windows server 2008 DEBUG build enviroment
I printed the words in step 7 and clicked enter and repeated it with step 8,9,10.
Nov 16 '09 #8
Markus
6,050 Expert 4TB
Please make the effort and read the tutorials available on the SWIG website. For information on how to integrate SWIG with VS, see this article.

Mark.
Nov 16 '09 #9
urib
14
1)f you mean to the tutorial in the link in this post then it does not talk about PHP but about other langauges that I do not know(I also do not know PHP)

http://www.swig.org/tutorial.html

I see
Building a Tcl module
Building a Python module
Building a Perl module
Building a Java module
Building a C# module

I am simply not sure which link I need to read.

2)The article that you give talk about microsoft visual C++2005 and older versions of C.

Did not try it but
I am not sure if the part about Visual C++2005 is also good for
Visual C++2008
Nov 16 '09 #10
Dheeraj Joshi
1,123 Expert 1GB
Try this link...

SWIG AND PHP

Regards
Dheeraj Joshi
Nov 16 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.