|
|
Can Php Interact With A Visual Basic App On A Server | ||
Discussion by it01y2 with 12 Replies.
Last Update: February 10, 2010, 9:41 am | |||
![]() |
|
|
1. The PHP program writes some data to a file in some format.
2. The VB program constantly sees if a file is there for it to read.
3. The VB program processes it and puts the result back in another file.
4. The VB program deletes the original file. (so that the PHP program can create a new one later)
5. The PHP program opens the file the VB program wrote, and has the results.
6. The PHP program deletes the file.
Another way I could see this working is using a Winsock control in the VB program, and then using the socket functions of PHP to connect to it and process the request. This technique seems more practical now that I think about it. Here is how I would write this one.
1. The VB program is constantly listening for connections.
2. The PHP program connects to the IP address 127.0.0.1 (your computers IP) or localhost
3. The PHP program sends what needs to be done to the VB one.
4. The VB program returns the data and closes the connection.
The technique I wrote above seems more practical because it can handle multiple requests, instead of just one file. It probably is slightly faster (by a very small amount) because the computer doesn't need to write to the hard disk constantly.
The opposite, using VB and calling a PHP program can be done. I am currently writing a game that will use this technique for match making. It works like this.
1. You have a PHP program that does a certain function and accepts its data through GET
CODE
<?PHP
$variable = $_GET['mode'];
// if you have the url, http://www.whateversite.com/phpprogram.php?mode=1, the $variable = 1.
PHP?>
2. The VB program uses the Inet control, and sends the request.
3. The PHP program would output its result using the print() or echo() variable.
I hope this helps you guys out a lot. I'll be happy to guide you along and answer any other questions you have.
Any good tutorials on that, or any good simple free programs that do the same? (open source possibly...)
Have a great day!
-Tom.
Traditionaly, Microsoft IIS web server, was used to host ASP pages, and Apache was used to host PHP pages... There is a plugin (or module) for IIS and PWS that allows processing of PHP, but it's not that good, and it is very limiting in power, i believe PHP works only in CGI mode... Anyways, not to stray from the topic...
There are few ways to connect VB with PHP scripts...
Least efficient is through file, as ghostrider said... It's inefficient, since it consumes much CPU time, and thus we'll forget about it (I tried similar approach once, for connecting VB program, with QB program... Not good)
Second method is by using MySQL for exchange of information... Connect VB to MySQL server, connect PHP script to MySQL server, and voila... Easy setup of information... This could be a good method, I'm using it for displaying some info on my site... May be non-efficient though, if too frequent queries should occur...
Third method, again mentioned by ghostrider, involves using socket functions of PHP, to connect it directly to your VB application... A good method, probably the best option... The second part of it, transmitting data to PHP script, I would use POST method, not GET... First, GET metod has a limitation to its length (2K I believe), and POST is used to transfer large quantities of data...
Here, I'm including code used to send data via POST methid, using Microsoft Internet Controls OCX... Just add it to your project, and use the following code:
CODE
Public Sub SendData(ByRef wb As WebBrowser, ByVal Params As String)Dim vPost As Variant
Dim vFlags As Variant
Dim vTarget As Variant
Dim vHeaders As Variant
Dim aByte() As Byte
Dim i As Long
' Params are in the following format <param-name>=<param-value>[&<param-name>=<param-value>[&...]]
PackBytes aByte(), Params
vPost = aByte
vFlags = &H2 Or &H4 Or &H8 Or &H10
vHeaders = "(anti-spam-(anti-spam-content-type:)) application/x-www-form-urlencoded" & vbCrLf
wb.Navigate "http://your-server/php-script.php", vFlags, vTarget, vPost, vHeaders
End Sub
Private Sub PackBytes(ByRef ByteArray() As Byte, ByVal PostData As String)
Dim i As Long
Dim j As Long
Dim c As String
j = Len(PostData) - 1
If j < 0 Then
Exit Sub
End If
ReDim ByteArray(j)
For i = 0 To j
c = Mid(PostData, i + 1, 1)
If c = Space(1) Then
c = "+"
End If
ByteArray(i) = Asc(c)
Next
End Sub
This code is sure to send data to your script, via POST methid. You can ofcourse parse resulting webpage, and control your VB application taht way too...
If you want, I can send you a DLL that you can use to connect with MySQL server, and read and write do MySQL databases, just PM me...
Hope this helped a bit...
Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do that (sadly
Cheers
QUOTE (Galahad)
Oh yeah, just remembered... Since Apache works (mostly, and preferably) on Linux, and VB applications can't do thati'm kinda noob programmer, but i found this post very interesting. i didn't remember that VB aps can be run only in windows environment so i posted this question. i won't learn Vb but C and C++ since it can be compiled both for linux and windows environments.
My logic suggests me that C programs could be written to interact with php, and it's kinda logical couse php is written in C (i guess). So if at any time of my life i want to make an application in C to interact with PHP what would be the right way to do that!? It is so soon to talk about that for me, but you don't need to answer right now, and maybe there is more ppl interested in this subject so you could writte anyway.
What is the difference between running PHP as Module or as CGI script, how is all of that conected with basic root program of PHP (what is root program of PHP, how can i start modifiying php, and is it smart to do that, just for fun, and for learning purposes)
thanks
CODE
$Somename = $_GET['someurl name'];or
CODE
$Somename = $_POST['someurl name'];But its better make code with GET Method
In visualBasic You can generate one HTML page and form and make it for send data form game to server
i read Galahad's post You can use it him code for vb
QUOTE (ghostrider)
I've been programming in VB for ten years, can you describe what you are trying to do with a little more detail? I think it is possible to do. PM me or post back and I'll help you out.Link: view Post: 294489
hi Ghostrider,
u seemed to be very experienced in programming, so let's straight to the point,
now i'm building a php webbased application, n thinkin about goin to integrate it with an sms feature,
got the device, and unfortunately the API provided by the device is written in VB, which is something new for me,
my question is, is it possible to call a VB module in php script? i know the most common answer is not possible,
because VB is on the server side, and php is on the client side, but i'm sure there is a way, i just dun know how.
a brief explanation about my program (pretty simple actually):
there is a php page, with the detailed info about a product (type, weight, price, etc). n down below, there is a button "Interested",
what i want the program do is, when the user click that button, the php store an information into DB (MySQL), and at the same time, it trigger the VB module, to retrieve the same data and initiate the GSM modem to send sms containing the data. so most likely the data is just goin to be a string sayin "this user is interested in this product , bla bla bla..".
i hope u could briefly imagine and eventually can help me with this.
many thanks in advance though,
QUOTE (it01y2)
I am currently making a game. And I want to use a command through php to ineract with a visual basic app on my server. Is it possible? and how?Link: view Post: 294467
Hi!
It is indeed possible for PHP and Visual Basic to interact, but it is up to you to decide how you want to do it. Here are a couple of ways you can do this:
1. Write to a file using one language and read using the other
2. Create a webservice on one platform that you can call from the other
3. Use TCP/IP sockets for communication between the two
4. Use a message broker application or a message queue - MSMQ is available with MS Windows
5. Store and read values from a database
Most of the applications that I work with use a database for storage so I simply have to create a database trigger to copy the values across the applications' tables.
Regards,
Nitin
QUOTE (hirou)
hi Ghostrider,u seemed to be very experienced in programming, so let's straight to the point,
now i'm building a php webbased application, n thinkin about goin to integrate it with an sms feature,
got the device, and unfortunately the API provided by the device is written in VB, which is something new for me,
my question is, is it possible to call a VB module in php script? i know the most common answer is not possible,
because VB is on the server side, and php is on the client side, but i'm sure there is a way, i just dun know how.
a brief explanation about my program (pretty simple actually):
there is a php page, with the detailed info about a product (type, weight, price, etc). n down below, there is a button "Interested",
what i want the program do is, when the user click that button, the php store an information into DB (MySQL), and at the same time, it trigger the VB module, to retrieve the same data and initiate the GSM modem to send sms containing the data. so most likely the data is just goin to be a string sayin "this user is interested in this product , bla bla bla..".
i hope u could briefly imagine and eventually can help me with this.
many thanks in advance though,
Link: view Post: 443351
Hi Guys...
I have a similar requirement to call VB applications through PHP pages...Please let me know if I can call VB or a .Net application using PHP web pages.
TIA
-Sam49-
Web services can be used to communicate across different platforms. You can use PHP to create web services (perhaps using the nuSOAP?) and can then consume those web services using Visual Basic. Microsoft Visual Studio makes working with web services a breeze - it's just like making a method call to a regular class method. You can also do the reverse by creating a web service in Visual Basic and consume the service through PHP. There are different libraries/extensions that you can use within PHP to create and consume web service and there are trade-offs that you have to make for each one so you might want to take a look at which one is right for you. The nuSOAP library enables you to create and consume web services using PHP calls. In additional, you can also generate the web service descriptor (WSDL) automatically so the web service description always matches the service that you are building. The downside of using nuSOAP is that it is not as actively maintained. The PEAR-SOAP library is also PHP based and is comparable to nuSOAP. The SOAP extension for PHP requires server-side configuration/installation and therefore may not be an option if your web hosting service does not provide the extension, however the PHP SOAP extension is also the quickest since it is built using compiled C code.
Making calls across different platforms generally involves overhead. In fact, if you are making web service calls, there's an overhead even if you are using the same platform on both ends due to the conversion to XML.
Similar Topics:
Visual Basic 6.0 Help Needed
Mysql In Visual Basic
Visual Basic For The Web?
Making A New Bbcode For Smf 1.09 (0)
|
(5) Help Needed With Directory/file Listing Code Infinite Loop Made an infinite loop but why is this so?
|
Loading...
HOME 






