Solved

Send a file from my server to a page on another server to be processed and return me an xml reply..

Posted on 2013-12-23
12
236 Views
Last Modified: 2013-12-28
Hi,

My exact case :

When  a site user tries to register , he uploads a word file ( his CV).
Then  this word  file is processed to extract some data from it ..

This is working fine till now.
But what I want , Is , after he click submit the  registration form, his  data sent to the server will have some processing and some data to be inserted in the DB , and to open a connection with another  server to send the uploaded file to it , to be processed on the second server and then send me the reply as XML file .. to be processed again on  my original file..

What  are the suggestions for doing that ?
Reason:  My original server is running on Linux , And I the file processing to be on windows to be able to use the COM class which is only available on the windows version of PHP.
And I don't prefer to transfer my site to a windows hosting due to security reasons.

Any help?
0
Comment
Question by:darroosh
  • 6
  • 5
12 Comments
 
LVL 20

Expert Comment

by:edster9999
Comment Utility
First of all - think about this the other way round.   Keep the file in linux.  Why would you be going to a windows server ??? Anything Windows can do, Linux can do better and faster (well almost anything).
There are a lot of PHP libraries and plugins to read MS files and talk to databases - try one of those before you jump into windows.

If you do need to move it to another server - either a linux one or a windows one, then you need to copy the file to that box (unless they have access to a shared file area. Once you have the file over (either on a share or by passing it to a web page as submitted form data) then you can reference the file by its name.
0
 

Author Comment

by:darroosh
Comment Utility
Please read the first line of this page:
http://www.php.net/manual/en/com.requirements.php

COM functions are only available for the Windows version of PHP.
And this is the reason I need windows server...


About the PHP libraries you are talking about , I tried most of the free ones with a result not 100% matching what I need ..   always I face some problem..So I decided to create my own library. I already created it , and it's working fine with my requirements giving me about 100 % of my job ( using COM class was the best results ) ..

About  the second half of your reply, I didn't get it .. I want the form data to be sent to a page on my original server to be processed there  , then this page should open a connection with another page on another server sending it the file to be processed there and wait the response which will be XML file..
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
You might want to read up on client/server protocols.  What you're designing is likely to look like a camel in a horse race.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

Executive summary: You do not "send" files to another machine.  The other machine must request the file.  You have some freedom to get around this rule of HTTP if you go outside of the HTTP protocols. For example, you might be able to open FTP connections between the machines.  This is a research project, so plan accordingly as you budget your time.

This question from last month is still open.  Have you gotten COM working now?
0
 

Author Comment

by:darroosh
Comment Utility
Your article is excellent, Thanks for it, I read some of it and I will continue to read the rest.

Before reading your reply, I was able to do what I want using cURL in PHP..
This page helped me :
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/

What is your opinion in that ?

But I need explanation why you say:
What you're designing is likely to look like a camel in a horse race.

About my COM problem, Unfortunately , It have not been solved! I just  changed the server and I'm still trying to check it in a new one.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks.  The use of cURL to make a POST request seems feasible, but I think if I wanted to use COM, I would just put the entire application on a Windows server.  I don't think Windows is inherently any less secure.  Having two machines feels more complicated to me.

As I think about this problem with two machines, it seems to take the shape of a web service.  The Windows machine might expose an API that is available via a POST request.

Linux machine:
1. base64_encode() the Word document
2. POST the encoded Word document to the Windows machine
3. sleep() for a moment to allow Windows machine to work
4. Read the response from Windows machine

Windows machine:
1. base64_decode() the document, turning it back into Word document
2. Do processing as needed with COM
3. Write the response as if it were browser output

I believe this is feasible with either cURL or fsockopen().  I think I would try to avoid sending a file, and just send the contents of the file as a character string.
0
 

Author Comment

by:darroosh
Comment Utility
Thank you for your help ..


Yes it looks  like a web service , that's what i really thought about..
Because my case is that  I need a windows component , But I prefer linux stability and  security over  windows . So I tried that to get  both benefits.

Anyway,
I tried my real code and had a small test.
File uploaded  from my local machine to the linux server , the linux server sent  the file  to the windows server, the windows server just saves the file and return some data about it ( type, ext , size)..

The overall time spent for that : 0.00876092910767 .
Time will be  spent in the  windows  processing is n't an addition to the script execution  time, because it's a must  to be  processed either on linux or on windows..


About avoiding to send the file and send its contents . that's exactly what I can't do , Because I send the file to the windows machine to get its contents using the windows COM..  On the linux machine(missing COM) , when I try to get  the file contents, sometimes it's extracted with accuracy less than 100%, and If I could make it 100%, so the windows machine is useless !


Conclusion, What is your opinion, does my solution to make it like web service make sense ???
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
Yes, it makes sense.  There are often many ways to solve a problem and rarely one "perfect" way, but I think you've got a pretty good design for this problem.  You might consider putting it all behind HTTPS protocols if security is an issue.  Just a thought...

Best regards, ~Ray
0
 

Author Comment

by:darroosh
Comment Utility
Does HTTPS adds any time for transferring data ?

Also how to do that ?
Should buy an SSL certificate on the windows machine to be able to call it using HTTPS ?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Does HTTPS adds any time for transferring data ?
Yes, it is noticeably slower on very large documents, but typically the delay is not enough to worry about.  Talk to your hosting company about how to set this up.  There is usually a modest cost.

Thanks for the points and thanks for using EE, ~Ray
0
 

Author Comment

by:darroosh
Comment Utility
Sorry, but another questions:

You said that I must base64_encode my file before  sending it to the server ..
Why this is important ?
And what if I didn't encode it ..
And how to encode it  ?

Regards
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Bas64_Encode() and Base64_Decode() work together to enable you to send binary data across interfaces that are not "8-bit clean," such as mail bodies or SQL connections.  Certain characters have meaning to these unclean interfaces, and binary data such as might be generated in external documents could contain something like a "stop" character.  Check the man page links for details.
0
 

Author Comment

by:darroosh
Comment Utility
In our case , does the two machines are 8-bit clean or not ?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now