473,405 Members | 2,344 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,405 software developers and data experts.

How to Convert C to PHP?

KeredDrahcir
426 256MB
I worked in C a long time ago and touched on C++ however I now use PHP. I have some free C source code for a program but I'd like to covert it to PHP.

Is there any software that would do this or any person who would do it.

Failing either of these, is there anyway for running the C program on the internet?
Feb 19 '13 #1
19 12509
Dormilich
8,658 Expert Mod 8TB
is there anyway for running the C program on the internet?
sure, make the web server execute the C application and return its output (in the end PHP does exactly that, it’s a C(++) application that is registered in the web server (e.g. via module or FastCGI) and its output is sent back to the server which sends it back to the client.)
Feb 20 '13 #2
KeredDrahcir
426 256MB
How do I make the web server run the C program and return its output?
Feb 24 '13 #3
Dormilich
8,658 Expert Mod 8TB
simple answer, by calling it from the server.

longer answer, you register your C application in the server configuration that when a certain event happens (e.g. a HTTP request) the server calls the C app through the OS and passes it the necessary information.

take for example PHP. PHP is an application written in C, when a HTTP request (for a file with the .php extension) occurs, the web server calls the PHP executable and passes it some data, then PHP executes based on the given data (the PHP script file mentioned in the request being one of them) and returns the result to the web server, which passes that back to the requesting User agent.
Feb 24 '13 #4
KeredDrahcir
426 256MB
Do I need to compile the C file because C complies to an executable file, or do I call the executable file?
Mar 19 '13 #5
r035198x
13,262 8TB
Well that depends on how you want the interaction to happen.

1.) If you want to call the C program from PHP then yes you compile and create the binary as you would do for a C application release and install it on the OS. Then you call it from your PHP using the system (http://php.net/manual/en/function.system.php) command. You have to be careful how you call the command here because if you are dependent on internet input it can be manipulated to execute harmful commands on your system so only call commands you have defined and make proper checks before calling.

2.) You could write an Extension as explained in the tutorials starting here :http://devzone.zend.com/303/extensio...-php-and-zend/

3.) If you don't use PHP at all and just call the C program from the webserver then you need to have the C application properly installed as required for 1.) above as well.
Mar 19 '13 #6
KeredDrahcir
426 256MB
I had a look at system and exec. The C program may be required to take hundreds of user inputs possibly close to 500 and output the result for each before it completes. Is there a way to execute it through HTML or JavaScript since php will wait until the program is finished before displaying it which doesn't help.
Mar 19 '13 #7
r035198x
13,262 8TB
It would be dangerous to allow Javascript direct access to your system shell. Couldn't you make AJAX requests to a PHP script that does the validation and call for each request?
Also 500 separate requests for a user sounds like a lot. You'd certainly struggle to display all 500 results to the user at the same time unless if they are being aggregated somehow.
Mar 19 '13 #8
KeredDrahcir
426 256MB
I'm afraid I know know anything about AJAX. In terms to the 500 seperate requests, it would ask them a question and then based on the result of that question, ask them another. I know that my traget audeince would be quite happy to answer all these questions. They can even save past way through and continue later.
Mar 19 '13 #9
r035198x
13,262 8TB
Then you don't need AJAX and you should let PHP wait for each response from the C program because you need to use the result in your next question to the user anyway.
Mar 19 '13 #10
KeredDrahcir
426 256MB
I thought php would only show what the program is going to display after it has finished. If the user has to answer several questions how do they know what they will be?
After each question, they will get different questions depending upon their answer to the previous question.
Mar 19 '13 #11
r035198x
13,262 8TB
Erm, it's you who decides what you want PHP to display to the user and when so it's all up to your requirements.
Remember that I have no idea what your C program does or how often it should be called for each user question. You just asked for how to call C from PHP. All I can say is that it's you who decides when to let PHP call the C program and that ii up to your requirements.
Mar 19 '13 #12
KeredDrahcir
426 256MB
All I want to do is call the C program once to display in the browser so the user can go through it until it had finished.
Mar 19 '13 #13
r035198x
13,262 8TB
Do you mean that your C program is interactive and you want the user interaction part to happen via the browser? Then you need to be able to provide input to the program and read its output streams without shutting it down. The C forum will help you with that.
Mar 19 '13 #14
Dormilich
8,658 Expert Mod 8TB
a C programme cannot be displayed in a browser, that’s not what browsers are supposed to do. they have to display HTML and execute JavaScript.
if you want the user to use the C programme directly, make the user install it on his computer.
Mar 19 '13 #15
KeredDrahcir
426 256MB
That's exactly what I want to do r035198x. It's interactive. Sorry I should have made that clear.

I didn't think I could display a C program in the browser Dormilich which I why I wanted to convert it to php in the first place.
I we've gone in a circle here. Is there any software that could convert C to php or are there any persons out there who do it?
Mar 19 '13 #16
r035198x
13,262 8TB
You never convert from one language to another. Either you keep the C program and just interact with it from PHP or you rewrite it completely in PHP.
Mar 19 '13 #17
KeredDrahcir
426 256MB
In that case, are there people anywhere who could rewrite it in php? Can I run a JavaScript script which would run the C program since JavaScript is client side?
Mar 19 '13 #18
r035198x
13,262 8TB
The C program will be running server side not client where Javascript runs.

PHP does run on the server that's why we suggested you call the C from PHP and call the PHP from HTML/Javascript. Just adapt your C program so that it can interact with another program (PHP) and you're done.
Mar 19 '13 #19
KeredDrahcir
426 256MB
That's the bit I can't do, adjust the C program since it's free to use program but not mine and it's year since I used C and can't remember how to do it anymore.
Apr 19 '13 #20

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

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
6
by: Ken Fine | last post by:
This is a basic question. What is the difference between casting and using the Convert.ToXXX methods, from the standpoint of the compiler, in terms of performance, and in other ways? e.g. ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.