Establish & Receive Calls via a GSM modem in PHP - php

I am having a CRM (Customer Relationship Management Software) built on php and running it on localhost (windows XP system). This contains the list of my clients. I want to be able to call these clients directly from my CRM and keep a log of the same. (Call time, call duration and record the calls). For incoming calls, I should be able to link it to my CRM, display the client details and log the data.
I have a voice enabled 3G GSM Modem (with USB connector) which can be used for this purpose. From my search, I understand I would need to send AT commands from PHP to interact with the modem. But I am not able to move ahead as I am completely new to this. I have never done any device interfacing before this.
Can you help me to understand how can I go about solving the above issue? Any leads, resources in this direction will be of great help.

I wouldn't try to do this with pure PHP since then you would have to have PHP interface with the hardware through the webserver, which can be a pain, if it is manageable at all. There are (edit) three options in my view:
1: AKA the hard way:
Write a PHP extension in C that does what you want, but this would mean a lot of programming for a relative small task.
2: The eas[y/ier] way:
Find a program (Maybe Skype?) that can do voice communication with your modem and has an API or a CLI so you can make PHP run:
voiceprogram.exe --call=555-000-5555 --saveTo=client1_20113103_1200.mp3
This allows the application to do what it's good as and only use PHP as the controller. The resulting MP3 (or Wav, OGG, etc) can be saved back to the CRM.
3: Other options
If you are able to program in a different language that does communicate easily with your modem you can write some custom code that can be triggered by PHP (sockets/SOAP/CLI) and handles the call. When finished it can 'POST' the call information back to your PHP script.
The first 2 solutions only work when the CRM runs on localhost, if you plan on using this in a shared network environment complexity will go up. The last option, if done correctly, can be used in a shared environment.

Related

Serve PHP/MySQL with Apache/Nginx/FastCGI on Swift (iOS)

At work we have a enterprise store, meaning we can kind of bypass most of the main Apple App Store regulations. We have a special data-management system written in CodeIgniter with MySQL as the database engine serving the framework on Apache.
We are now getting more and more questions to run the system offline on the iPad. I've tried to use LocalStorage and such, yet it's just not enough and stable enough (WebStorage/WebSQL glitchy) and the allowed storage size is too small to fit all offline buffered data into.
I know this is very ugly, but as we mostly know, customers always find the most weird ways of requesting features and our sales team always manages to push it through without consulting us :P.
I did browse Google/DuckDuckGo and CocoaPods for a while, but I can't really find anything combining PHP serving within Swift (Objective-C would be ok too) serving it on Apache/Nginx/FastCGI with MySQL (I could substitute this with SQLite3).
I was wondering if anyone has experience with running an internal server in Swift/Objective-C in this fashion.
If you wish to keep your current stack of technologies, you could use something like Realm. It is a replacement for Core Data, and it allows you to easily create objects from JSON REST API and store it to the local database. But you still have to write some application specific code to keep data on the mobile device in sync with the server, and you have to have RESTful services that produce JSON on the server.
If you're ready to switch your persistence stack, you could use Couchbase Mobile that allows you to transparently sync your data on the device with data in your backend database, back and forth. But then you have to use Couchbase on the server.
If you want server-side Objective-C, look at https://github.com/depinette/backtoweb
I have not updated this framework in a while but it worked for me.
It's based on fastcgi and it can be used with the Apache server integrated with OSX.
I suppose you could use swift instead of Objective-C.

Blackberry: How to get a particular parameter/variable from php in java?

I'm new to php. Please can anyone guide me through this? I have a php where I'm having some variables as sort of flags. When those flags are set/true, I start those services in my Blackberry otherwise not. My application keeps on listening to my php and when those flags are true, it starts the respective services, others are kept off. How can I achieve this? Thanks.
It sounds like you want push notifications.
If you do it by "listening" to a php page, you're going to have to repeatedly make requests to that php page. You could do long-polling, but that's not going to work very well on a cell phone... each time the connection disconnects, you need to connect again, and it's messy to write all that client side code yourself. PHP also isn't a great language for push notifications, because on the web-server side, there's no easy way to push information to php once php has a connection from your blackberry. Since PHP isn't multithreaded (in typical webserver configurations), you'll again most likely be busy-polling some notification in a file on the disk of the web server, rather than just receiving and handling a notification as from a message queue or socket/io connection.
Most phone development kits have built in APIs to handle push notifications. From what I understand, re-using these systems leverages existing architecture, meaning the phone only connects to one server, which saves battery life.
I've never done any blackberry development, but you should probably start by searching for information/tutorials on implementing push notifications in blackberry.
If I'm wrong, and you just want to be able to get configuration options for your blackberry app, then that's easy. Your php page just spits out the information in any format the client (blackberry) can read (like json, xml, key=value, whatever), blackberry parses it, and acts on it.

Webserver from linux(debian) sends data to an Ip in a network

Hi,
From the image above, I have a webserver a linux machine and client/device.. Now i need for this 3 to communicate. The webserver sends data to an ip address(client/device) based on button pressed on the webpage. but before the data is sent, the data must first access the linux machine, the machine then sends the data down to the device which then the device reads the data and act based on the command sent.. then the device sends back data to the linux machine which then the linux machine sends it to the webserver for ack'd. meaning data is received by the device without any problems.
Php is for the webserver. Now how will php sends data to an ip adress.
The linux machine handles all requests and sends everything down to the device and when the device got the data it will send a data to linux machine which then machine sends an ok to the webserver that the data arrived succesfully.(I read about socket programming and i think of creating an application that reads requests.) or if you have any idea how can i do this?.
How can the device read a data sent by the webserver?..
Thanks,
EDIT: The device is not connected to the linux machine. the device is only connnected via the ethernet cable.
Let's call the topmost machine 'Server', the middle machine 'Controller' and the bottom machine 'Device'. It does not matter if the device is a peripheral (say, USB or serial device), or a computer.
The first task is to get the Controller to query the Device. The best way to do this really depends on the Device. If you consider things like USB audio/video devices, they need to be tuned, then they send a continuous stream of data. Things like temperature or humidity sensors are told to do a measurement, then they respond with data.
Usually you write the required functions into a small library, and verify it works using command line tools. In some cases the library may not be necessary, for example if the Device is already supported by the kernel in Controller, and the information is trivially available. (For example, consider the temperature sensors in hard drives: if Device(s) are hard disks, then Controller can simply use the command hddtemp /dev/sda to get the temperature of the /dev/sda (first SATA/ATA/SCSI hard disk). I'd expect the end user to be able to pick which hard disks she is interested in, so that choice would have to flow from Server to Controller.)
Next, you write a service that will run on the Controller. This service will incorporate the library functions already written and tested, so it can easily access the Device. (This way you know the Controller-Device communication works, and don't need to worry about it. One thing at a time.)
There are many different designs for the service, from plain TCP/IP or UDP/IP sockets to Remote Procedure Calls (RPC), to high-level protocols like HTTP. In recent years, the last, using HTTP, has become more and more common, with responses being XML, plain text, or binary media (usually images). The idea is to have the service be basically just another web server that can access the Device directly. Security is simpler, because it does not need to be world-accessible: it can very well only answer to requests coming from the Server only. I've written such services using basic shell scripting (Bash), PHP (both PHP-CGI and command-line PHP, PHP-CLI), and C, among others. The best choice depends on the details, really. I personally prefer either a simple text-based TCP/IP socket, or HTTP.
On the Server, you can write a PHP page, that connects to Controller, requesting whatever it wants to request (usually depends on user data, first checked for sanity and safety, of course). PHP has easy built-in facilities for doing both HTTP requests and connecting using raw TCP/IP, so it suits quite well for this. If HTTP protocol wrappers are enabled, then it is just $handle = fopen("http://192.168.x.x/myservice?param1=" . urlencode($param1) . "&param2=" . urlencode($param2), "r+b");. To get a socket connection, you use the fsockopen() function instead. (For details, see fopen(), http wrappers, and fsockopen() at the PHP Function Reference at www.php.net.)
In practice the PHP page code first creates a connection to the Controller. Then it sends a request, containing the relevant sanitized commands/parameters received from the end user. Then it waits for the Controller to respond with the results (by simply reading the response), then closes the connection. The response should contain all the data needed, so the PHP page is free to construct the page to the end user.
None of this is really difficult, but there is a lot to do. I've found the Controller-Device communication to require the most work; after that is done, the rest has always been quite straightforward.
If you can provide more details what the Controller-Device connection is, what kind of data (text? numbers? images? a lot of binary data?) the Device provides, and what kind of parameters/commands (just "one result, please?", basic commands like "move up", "where are you?") do you expect you need to send to the Controller/Device, I could perhaps be more specific.
Also, are you limited to PHP, or would you be comfortable writing the Controller service using C? I've found that to be a very good combination myself.
Edited to add:
In a nutshell, the three points can be answered as follows:
Either using fopen("http://ip.add.re.ss:port/", "r+b"); if using the HTTP protocol and PHP is configured to allow http wrappers (they usually are), or using fsockopen(). See the PHP documentation linked above for details.
With an IP-connected Device, Controller is basically a relay or translator. Usually this means a daemon running on Controller, managing incoming requests from Server (or Servers), and responses from Device (or Devices). This is more common when there are a varying number of Devices, and/or more than one interface is needed. In practice, the Controller runs a daemon just like described above, except the protocols may be standard or simple enough so there is no need to write a library.
The PHP running on the Server must contain the request details (exactly what is desired) to the Controller. The Controller must pass them on to the Device. If the Controller provides a http URL for the PHPs on the server connect to, it can parse the query parameters, and translate them into a format the Device understands.
One particular issue in practice is to handle concurrent accesses. There is usually only a single connection from Controller to Device, but more than one PHP might connect to the Controller simultaneously. So there is some book-keeping involved.
In some cases the Device provides a continuous stream of data (or regular updates of data) to the Controller, and the Controller simply keeps tabs on it. When a PHP running on the Server queries something from the Controller, the Controller simply looks up the latest data (without contacting the Device at all, just receiving the data as normal), and responds with it. Here, it is common to include a timestamp, or better yet, the age of the data, in the response from Controller to Server.
You really should add some details to your question. (I suspect the downvote is due to lack of details.) You don't need to tell us the exact make and model of the Device, only whether it is a receiver (TV? radio? weather station?) or a sensor cluster or a door lock, and if you know any details on the communications protocols (which ones)? Thus far, we only know it uses IP. That does not help at all, just about everything uses IP nowadays. This is also why my answer is so vague; I'd like to be more precise, but you do not provide enough information for me to do so.

CardScan integration with PHP

I have to integrate my CardScan (from http://cardscan.com/) with my PHP so I can get any information from the card scanned with the device.
Any clue about where I should start?
--
I'll try to integrate it with my Ubuntu development enviroment, and the device will be conected to my computer via USB.
--
I'm givin a try to SANE, but it doesn't find the device: https://askubuntu.com/questions/24297/problem-with-sane-and-cardscan-cant-find-the-device
You've not provided a lot of the information we would need to answer your question accurately/completely.
PHP is usually run on a webserver to provide a UI via a browser over HTTP - in this architecture the PHP code has no access to the hardware on the client. It is possible to write CLI / Daemon and even GUI applications using PHP integrating directly with the window manager - is this what you are talking about? What OS will this run on?
Since CardScan appears to be a simple scanner, then if the PHP code is running on the machine where the scanner is attached, then it should simply be a matter of running an external program to talk to the scanner and capture the image.
for Linux/Unix use SANE
for MSWindows, use a CLI TWAIN tool - e.g. twain commander
Apple MacOs seems to use a twain API - but you'll need to search to find tools - however it also supports SANE
Start by asking them if they have an API, webservice, public interface or a connector that communicates with the outside world. PHP is a web programming language. If this card reader is a phisical device maybe Python or C++ are better for this job.
From what I see their are synchronizing the cards with Outlook so they must have some software outputing information. Try to figure out what is the format and if is available to intercept somewhere.
Now this depends on how the card-reader interfaces out the data from the scanned card. My experience with magnetic stripe readers is that the data is output as keyboard type input.
I would suggest that you need to develop some form of Client Side app - to handle the input, and then post data to the relevant PHP modules on a webserver.
A good start would be the developer manuals for the hardware to understand how it interfaces.

Communication between PHP and application

I'm playing with an embedded Linux device and looking for a way to get my application code to communicate with a web interface. I need to show some status information from the application on the devices web interface and also would like to have a way to inform the application of any user actions like uploaded files etc. PHP-seems to be a good way to make the interface, but the communication part is harder. I have found the following options, but not sure which would be the easiest and most convenient to use.
Sockets. Have to enable sockets for the PHP first to try this. Don't know if enabling will take much more space.
Database. Seems like an overkill solution.
Shared file. Seems like a lot of work.
Named pipes. Tried this with some success, but not sure if there will be problems with for example on simultaneous page loads. Maybe sockets are easier?
What would be the best way to go? Is there something I'm totally missing? How is this done in those numerous commercial Linux based network switches?
I recently did something very similar using sockets, and it worked really well. I had a Java application that communicates with the device, which listened on a server socket, and the PHP application was the client.
So in your case, the PHP client would initialize the connection, and then the server can reply with the status of the device.
There's plenty of tutorials on how to do client/server socket communication with most languages, so it shouldn't take too long to figure out.
What kind of device is it?
If you work with something like a shared file, how will the device be updated?
How will named pipes run into concurrency problems that sockets will avoid?
In terms of communication from the device to PHP, a file seems perfect. PHP can use something basic like file_get_contents(), the device can just write to the file. If you're worried about the moment in time the file is updated to a quick length check.
In terms of PHP informing the device of what to do, I'm also leaning towards files. Have the device watch a directory, and have the script create a file there with something like file_put_contents($path . uniqid(), $command); That way should two scripts run at the exact sime time, you simply have two files for the device to work with.
Embedded linux boxes for routing with web interface don't use PHP. They use CGI and have shell scripts deliver the web page.
For getting information from the application to the web interface, the Shared file option seems most reasonable to me. The application can just write information into the file which is read by PHP.
The other way round it looks not so good at first. PHP supports locking of files, but it most probably doesn't work on a system level. Perhaps one solution is that in fact every PHP script which has information for the application creates it own file (with a unique id filename, e.g. based on timestamp + random value). The application could watch a designated directory for these files to pop-up. After processing them, it could just delete them. For that, the application only needs write permission on the directory (so file ownership is not an issue).
If possible, use shell scripts.
I did something similar, i wrote a video surveillance application. The video part is handled by motion (a great FOSS package). The application is a turn-key solution on standardized hardware, used to monitor slot-machine casinos. It serves as a kiosk system locally and is accessible via internet. I wrote all UI code in PHP, the local display is a tightly locked down KDE desktop with a full screen browser defaulting to localhost. I used shell scripts to interact with motion and the OS.
On a second thought:
If you can use self-compiled applications on the device: Write a simple program that returns the value you want and use PHP's exec() or passthru() or system().

Categories