Comments (5)
Although I think Kevin wanted to make php.js a primarily client-side library, he has always been open to our storing functions in the experimental section (or allowing configuration coordination via the php_js global, so someone could call ini_set() say to specify a server-side environment). So, yes, unless Kevin has objections, I'd say absolutely, at least for adding to the experimental section or adding support via configuration. Though I hope it may be possible to implement with CommonJS (though without knowing much myself, it seems one would have to choose between synchronous and asynchronous APIs?)
from locutus.
Yes I think setting environment and having functions error out if it is not compatible is the way to fly. _workbench
can be the workspace for that, _expirimental
the place for testing before we move to functions
.
it would be nice if we could support asynchronous apis because then you can actually leverage node's power. without it i'm not sure what the benefit would be. we'd have to do this in a consistent manner though, and by e.g. supplying a null
callback, a file_exists
would work synchronously. If we use the last argument for callbacks then we can be sure normal php code still runs in node so we don't break backwards compatibilty. thoughts?
from locutus.
I'm thinking node.js should be 1st class citizen. I released this npm even though many functions still target browser apis. Hence some uglyness.
But if it where up to me, all things echo default to console.log, all things file default to the fs module. And only if we detect those are not available to we do a stab at browser compatibility.
e.g. using sync ajax for a file_get_contents is just a mistake and allows beginners to do terrible things. But in having it in serverland would allow you to run .php
scripts on v8. Which is also terrible, but in a fun way π―
from locutus.
FYI, our file_get_contents
does support async in a PHP-ish way, via a callback within the context
arg:
file_get_contents(fileName, null, {// You can create this "resource" in a more PHP way by calling stream_create_context() here instead
// stream_options: {http: {}}, // Now optional as in PHP
stream_params: {
'phpjs.async': true,
notification: function () {
if (this.readyState === 4) {
alert(this.responseText);
}
}
}
});
...though it is not the most beautiful bird out there: :)
I surmise even the phpjs.async custom arg might not be necessary if the flags STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT
were supported here by PHP, but of course that makes it even uglier.
from locutus.
Thanks for reporting, and sorry for the long wait. This project and my motivation were in a bad spot. I recently did a lot of work to breathe new life into it (http://locutus.io/2016/05/announcing-locutus/).
But if it where up to me, all things echo default to console.log, all things file default to the fs module. And only if we detect those are not available to we do a stab at browser compatibility.
This bit made it into Locutus.
But in having it in serverland would allow you to run .php scripts on v8. Which is also terrible, but in a fun way π―
This goal didn't : )
But the good thing is Node is the primary target platform, with Browserify (and similar) as the recommended way to then target browsers.
from locutus.
Related Issues (20)
- bin2hex() fails with unicode characters like Γ Γ Γ Γ¦ ΓΈ Γ₯
- "contributing guidelines coding standards" url broken HOT 2
- [php/array/array_intersect.js] Simpler option HOT 3
- float bug and missing Q code HOT 2
- Linting upgrade HOT 1
- Failure to recognize some format and extract values in sscanf HOT 2
- [c/stdio/sprintf] %% consumes an extra arg HOT 5
- Question: Is strtotime Algorithmically Equivalent to the PHP Version? HOT 2
- hex2bin() Never Returns If More Than 1 Million Chars HOT 3
- Percentage for "similar_text" HOT 2
- Trying to get in touch regarding a security issue HOT 3
- strip_tags has some differences with php's version HOT 1
- Invalid syntax '/php/_helpers/_bc' in released '_locutus_shared/_locutus_shared_bc.js' HOT 2
- TypeError: Cannot read property '$locutus' of undefined HOT 1
- BUG : php function unserialize not working HOT 6
- php similar_text performance HOT 4
- Invalid serialization for floating numbers HOT 1
- Help - How install with Ionic? HOT 1
- bcmul is not working with decimal HOT 2
- fmod: toFixed() digits argument must be between 0 and 100
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from locutus.