In my previous question I tried to figure out how to identify a computer as accurate as possible. I think the best solution is the usage of Local Shared Objects a.k.a flash cookies. I would like to create a flash object, and two JavaScript or PHP functions to communicate with it. I did a research in the mayor search engines, but I did not found any solution to do that. I only want to store one variable in the object. I have no experience in ActionScripting...
Is there any way to create a local shared object and manipulate it with PHP or JS?
Related
I have an existing .NET application where most of the variables are stored using MemoryMappedFIles.
I am merging this now existing php functionality.
The porblem is now how to access the .NET variables from within php.
My current solution is based on implementing a pipe between both environments, but this does not hold when the load is high. Also, it is difficult to exchange structured data. I could try a relational database or a file in between, but this obviously adds overhead.
Any ideas on how to expose .NET variables into php ?
thanks.
May be its not a good idea. Can you store those memory mapped variable value into cookies and
you can access those value using PHP cookie variable .
eg. $_COOKIE['variable name'];
If variables are going to be used across environments then a shared data store would be a good solution. I do not know too much about .NET variables, and how one might expose them, but it sounds like it might be a bad idea, or at least a hassle.
When sharing data across environments the idea is to think of the data as being stored in one central place:
[.NET] [PHP]
\ /
|
[Data]
This architecture is good because you keep stuff separated, which means that each component can be handled (i.e. optimized and scaled) individually. It also means that you can swap out, or add, components. For example, if you in a month decide to hire a group of Ruby developers to build some project then they will not have to worry about the other languages, they just need to connect to the data store and run with it.
As for what data store to use, it does not have to be files or a relation database; depending on the kind of data, you can use in-memory key/value stores like redis or memcached, or if the data is more structured then maybe a document database like MongoDB would fit better.
I was looking to find a solution to our product. We have a geo-location, on a web based dashboard that does not have internet connection.
I was looking for a product that allows you to have local maps and a script, I found OpenLayers which seems cool although weights 22gb.
Do you know if there are other solutions to generate map locally that takes less space?
If I assume correctly, you are basically looking for an alternative to Google Maps, i.e. an alternative mapping service where you can use your own local data, right?
Now, based on your question, its hard to tell whether you
Want to develop something for yourself or buy/adopt an already implemented software
Are looking for the serverside (i.e. tiling/caching engine, geospatial database, etc) or for the clientside or for both
I could give you an example of a possible configuration if you want to develop a clientside application yourself, but that might not be what you are exactly looking for.
For the serverside, you could use MapServer, backed by a PostGIS spatial database (PostGIS is an enhancement of PostgreSQL), and then use a client side Javascript framework BASED on OpenLayers to develop your client application (i.e., the map viewer), such as Fusion, which is also based on the MooTools Javascript Library. You could also natively develop with OpenLayers. There are a lot of possibilities in the Open Source world, it just depends on the skill and time you have.
Also, have a look at OSGEO, in the right sidebar you'll find a lot of projects that are hosted by them. It definetely is your first address for Open Source web mapping solutions.
I'm new to OOP using PHP and the idea seems a little pointless in some ways. In non-webbased languages the object lives through-out the life of the program (from execution to exit). In this situation it make perfect sense because you build the class then initialize it at run-time where you can access it frequently as needed there after. However with web programming since the execution of an application might happen in many stages (page loads) the life of the object could end up being only a small portion of the time an application is being run. So it seems to me that the only option to keep objects alive during the course of the application's usage would be to store that object after initialization in a session variable. Is this common practice or are there other means by which to utilize the power of OOP in PHP more effectively?
PHP's website has an article that deals specifically with this: Serializing objects - objects in sessions. There's absolutely nothing wrong with serialize objects in your session but as this article suggests:
It is strongly recommended that if an
application serializes objects, for
use later in the application, that the
application include the class
definition for that object throughout
the application. Not doing so might
result in an object being unserialized
without a class definition...
It can still be very useful to manage objects with short, time-limited lifespans. Perhaps you want to communicate with two different kinds of database servers -- having objects that know how to build queries for those database servers can be very convenient. You, the programmer, get to interact with them in the same way, but behind the scenes one might use a unix domain socket to talk with a local PostgreSQL and the other might use a TCP connection from a session pool to talk with an Oracle instance.
Object-oriented programming exist to provide encapsulation and abstraction. Both are useful, even if the objects involved are created, live, and die, in .5 seconds.
With PHP you cannot keep an object alive, so you cannot store it in the session to gain performance. PHP will always serialize the object when writing to the session and deserialize it reading from the session.
To answer your question, yes it's very common to store an object in a session, but not for performance reasons. Storing and reading from the session are quiet fast, so i would only look for optimizations there, if you are sure this is a bottleneck.
Somethings to make sure you do if you take this approach is make sure your garbage collection is thoroughly working. Depending on what the object does it may store as quite a large record in which case you will be taking up quite a bit of disk/database storage.
I am a Codeigniter fan but those objects are huge and it would be highly unwise to store them. Security is another factor - if you are on a shared server and there is a chance of security credentials being held in the object then storing these may also be unwise.
I do store objects in a database but just make sure Garbage collection is working. If you use a database there is a bug in Ubuntu where the collection doesn't run - in which case you need to force it through ini_set.
Im a newbie PHP programmer and I have a few questions about creating a REST based API service.
Basically, its going to be a github open source project which is going to scrape various data off the web and offer it as an API in XML. Now here are my questions in terms of how should I or how can I do this.
1) Since there isnt a robust/same pattern for getting various data through scraping, what is the best way to actually output the xml?
I mean the PHP file would have various lines of extracting data from various points in the code and the file would be a lot of lines. Is it a good idea to type the code to output the result in there?
2) Is there a way to organize the scraping code in a sort of class?
I cant think of a way that would work besides linear approach where not even a function is created and you just apply functions (in general).
3) If theres a way to do that ^^ , how can it you output it?
Is there any other approach besides using another file and getting the contents from the main file and displaying the code through the secondary file.
4) If I were to offer the API in XML and JSON, is there a way to port from one result to another or will I have to manually create the fields in json or xml and place the content in there?
I might have more questions that might arise after these have been answered but I hope I get everything cleared up. Also, this is assuming that the results are not fetched from a DB so the data has to be scraped/tabulated on every request. (even though caching will be implemented later)
Thanks
This question is probably more appropriate on https://codereview.stackexchange.com/
Not to be rude, but a newbie programmer developing an API is like a first-year med student offering to do open-heart transplants for free. I understand that you believe that you can program, but if you intend to release publicly accessible code, you probably need more experience. Otherwise guys like me will muck through it and file bug reports ridiculing your code.
That said, if you want theory of good API design you should probably check out Head First Object Oriented Analysis and Design. You'll want to focus on these key concepts
Program to an Interface, not an Implementation
Encapsulate what varies
...and follow other good design principles.
...honestly, there's a lot to cover to good interface and good systems design. You can use this as a learning exercise, but let people know they shouldn't rely on your code. Though they should know that screen scraping is far more brittle and instable than web service API requests anyway, but many don't.
That said, to provide some initial guidance:
Yes, use OOP. Encapsulate the part that actually does the scraping (presumably using cURL) in a class. This will allow you to switch scraping engines transparently to the end user. Encapsulate your outputs in classes, which will allow for easy extension (i.e. if JSON output is in a Single Responsibility class and XML Output is in another, I can add RSS Output easily by making a new class without breaking your old code)
Think about the contracts your code must live up to. That will drive the interface. If you are scraping a particular type of data (say, sports scores for a given day), those should drive the types of operations available (i.e. function getSportsScoresForDate(date toGet))
Start with your most abstract/general operations at a top level interface, then use other interfaces that extend that interface. This allows users to have interfaces at different levels of granularity (i.e. class SensorDataInterface has a method getData(). HeartRateMonitorInterface extends SensorDataInterface and adds getDataForTimeInterval())
Is there a standard way of dealing with globally scoped variables in PHP? Session scoped?
From the research I've done, it looks like the options are mostly add-ons or external. APC might work, but would be limited to a single PHP instance and not so useful for a farm of servers. Memcached seems like it would work, but I was hoping to find something within PHP.
Does its stateless approach keep there from being a standard method for handling this?
A persistent layar is the only way to go with php. Either file based solution or database.
php natively doesn't provide any mechanism to do application scope variable.
You can do session variables with $_SESSION.