Jump to content

NotionCommotion

Members
  • Posts

    2,446
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by NotionCommotion

  1. php74 is installed as my primary php, but I am also working with a different framework that can only use php73 and set up a separate pool to deal with it. Recently, my installed composer1 told me I should upgrade to composer2 and I did so, but then found that the previously mentioned other framework also doesn't work with composer2 but only composer1. When updating a package with composer, sometimes I get composer errors or even worse no composer errors but PHP errors later on where classes don't exist, and I think it relates to using the wrong version of PHP (and maybe even composer). Is it always required to consistently use composer with a single version of PHP? Anything to worry about different versions of composer or will I just get a message. Any other best practices? Any issues how I set up composer below? Thanks! curl -sS https://getcomposer.org/installer | php # or if desired, use resulting composer.phar as: $ php (or php73) composer.phar update/install/etc chmod +x composer.phar sudo mv composer.phar /usr/local/bin/composer sudo ln -s /usr/local/bin/composer /usr/local/bin/composer2 curl -sS https://getcomposer.org/installer | php73 chmod +x composer.phar sudo mv composer.phar /usr/local/bin/composer2_73 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php --version=1.10.19 chmod +x composer.phar sudo mv composer.phar /usr/local/bin/composer1 php73 composer-setup.php --version=1.10.19 chmod +x composer.phar sudo mv composer.phar /usr/local/bin/composer1_73 rm composer-setup.php
  2. Thanks. Will stay away from that rabbit hole for now. Agree, but can/should their be some "middle-end" which can exist between the two? For much, the usage will be the same for each given task. For instance, when adding, deleting, or configuring one of these industrial controllers, or when viewing a trend of some environmental parameter, the same group of parameters must be provided, the user experience is the same, and there is no reason the layout needs to differ. As such, the HTML and JavaScript is the same as well as most if not all of the CSS. I understand that there still needs to be a data only backend to both separate concerns as well as allow a totally different UX, however, to reduce deployment time as well as eliminating the need to maintain similar codes bases, would be have something in the middle. If going down this path makes no sense, I suppose I could instead create a single class/object which has methods to get the associated HTML/JS/CSS for a given task, inject it into C5, Drupal, some 100% custom site, etc, and then configure endpoints in each of these individual web apps to call the appropriate method of this object. Or while IFRAMES are sometimes frowned on, maybe an option.
  3. Currently, I have custom endpoints in the C5 application which basically do two things: Make a cURL request to retrieve JSON which is converted into an array, and then uses Twig along with a specific Twig template for each endpoint which creates a portion of HTML. Define which JS/CSS resources should be included with the page. Then the HTML along with the JS/CSS resources are given to the core C5 application which renders the page as applicable. My thought was to move the functionality of creating the portion of HTML along along with the required resource paths to another server and call this endpoint instead of the one to provide JSON. Alternatively, maybe it requests just the template and JSON data and renders it itself. I haven't used XSLT and am just looking into it now, but don't see how it would be utilized. At first, I thought it was some sort of template engine like Twig, but don't still think so.
  4. Here is the scenario. I created a niche market API which provides environmental data. The data is obtained by industrial controllers which don't monitor anything by default, and the API has additional endpoints which are used to instruct the industrial controllers to start monitoring some parameter so the API can then start storing the trend data. The API primarily responds with JSON, however, a couple of endpoints support CSV data. For humans/webclients to access the data, I also created a webserver application which can be added to a Concrete5 (C5) CMS. I tried to make as many of its endpoints do nothing except receive the webclient's request, add a JSON Web Token to it which contains a unique identifier, forward it to the API using cURL, and return the response as is to the webclient. To limit the scope which needed to be created for the C5 application, the API has endpoints to return JSON which is used by JavaScript on the webclient for client-side validation, endpoints (actually, a different domain) to return static JavaScript/CSS/etc, and endpoints to restructure the JSON data to some more suitable format. I now am looking at creating different applications which does not use C5, but either are 100% custom or use some other CMS such as Drupal, etc. While I tried to limit the scope implemented on the C5 application, I have much more than I desire and will need to duplicate much for any future application. The primary scope I would like to remove from the webserver application relates to the HTML views and consists of templates which create HTML from JSON, the JavaScript which interacts with the HTML, and to a lesser degree controllers to determine the type of view (i.e. a list of records or one specific detail record). While the API will only be managed by myself, the intent is that the C5, 100% custom, etc webserver apps are installed and managed by others. Ideally, there is some existing Composer package for transforming JSON to HTML which is CMS agnostic, however, I don't know whether such exists. Also, while not 100% necessary, ideally this functionality could exist on my server and not the individual web application's server. Whether I build it myself or use some existing package, I expect it will need to do something like the following: The various webserver apps will have some routing table to proxy the request either to my JSON API server (complete) or my new "HTML API Server" (remaining discusses this portion). This HTML API server would generate the content either by making a cURL request to the main JSON API, or better yet since likely located on the same server have routing functional to make direct calls to the JSON API's methods, and return something like the following: { "html": "<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pharetra massa massa ultricies mi quis hendrerit dolor. Leo integer malesuada nunc vel risus commodo viverra.</div>", "javascript_files": [ "https://resources.myserver.com/someFile.js", "https://resources.myserver.com/someOtherFile.js" ], "css_files": [ "https://resources.myserver.com/someFile.css", "https://resources.myserver.com/someOtherFile.css" ] } The various applications would then take the HTML and resource files and insert them using their proprietary methods. EDIT. Also, thinking of using an IFRAME, however, definitely have concerns with doing so. My day job has nothing to do with software, however, am hoping to make it so. Before embarking on this task, I would like to know whether some existing framework exists and if not what general strategy (organization, caching, etc) I should take to develop it. Thanks
  5. Are you able to break you implementation into two basic applications? All your PHP/SQL script. It receives a HTTP request, calls the appropriate method to do something (CRUD) and either returns JSON or gives the PHP array to a view. Use something like https://www.slimframework.com/ to map between the request and the PHP script you execute. All your HTML, JS, CSS. If the above provides JSON, this will need to be setup to forward the request from the client to the above app, or you can set it up to be more integrated to have the above part just pass the resultant data array to this application. If so, you will then be able to hire someone to do just the second part of the application, and not have to worry about all your PHP/SQL scripts. The JSON route might be easier as it more isolates the two scopes of work. You also will be giving someone a very defined scope as each of your pages are already working and it will be very clear what you want from a UX perspective. You will, however, need to take steps to define the interaction between the two parts, and will need to give a narrative for each endpoint or maybe use swagger or similar to document. While you can make all your client script available, I wouldn't expect them to use any of the HTML and CSS but just to use some framework like bootstraps instead. I am sure it is a daunting task, but if the two scopes remain completely intertwined, it will be impossible to find someone without paying significant money. Or, maybe don't worry about it or better yet go with Strider's quick lipstick on a pig approach, and go forward with your venture.
  6. My typical approach to logging is as follows: openlog('PublicAPI', LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER | LOG_PERROR); syslog(LOG_INFO, 'some info'); syslog(LOG_ERR, 'some error'); And then when debugging script, I just use the following: journalctl -f -uphp73-php-fpm -uphp-fpm -ureact_php_systemctl_service While it works okay, often I get more content shown by journalctl that I would like. Another downfall is segfaults are not displayed, and the only way I have been able to view them is by not including a systemd unit (i.e. -u) and just using journalctl -f, but then I get way more content that I desire. Recently, I was running some script and none of my units (i.e. -uphp73-php-fpm -uphp-fpm -ureact_php_systemctl_service) filtered it. I then tried journalctl -f | grep PublicAPI, and while it worked, errors didn't show as red and I expect it just isn't the right way to do it. Next I tried journalctl -ft PublicAPI, and it seemed like a better approach. How should I be doing this? How can I filter just segfaults when something is not going right? Should I be filtering by unit and how can I identify what unit to use? Is a better approach to filter by user (not sure if possible)? Thanks
  7. When I first saw your code shown below, I thought that you were providing your server credentials or something. Investigated a little and saw that technically it should be valid. That being said, normally one will POST the credentials to the server, the server will query the DB and set a session. if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { ... }
  8. If you are receiving a string such as '"Id"=>"1"'. you are likely requesting the data incorrectly. A hack fix might be to explode('=>', $yourString), but really think you should get to the root of the issue. Any chance they are passing you JSON and it has some helper to make it look more human readable?
  9. Ah, good to know the documentation is right. Thanks
  10. Actually, looks like I need to use escapeshellarg(serialize($myArrayData));
  11. Never a messenger who provides accurate information (which it currently is)!
  12. I had been escaping my arguments before passing to exec(), and then type casting back on the other end. Recently needed to pass an array, and at first planned on json_encode(), but gave serialize/unserialize a try and discovered that it automatically took care of the type casting. The data is coming from me thus I am not (hopefully!) worried about malicious data. Any need to also use escapeshellarg() either before or after serializing? Thanks
  13. Is this a mistake in the documentation? I am running PHP7.4 and get warning: unserialize() expects parameter 2 to be array, bool given.
  14. Thanks requinix, Was going to comment on my reply to Barand that I felt PHP shouldn't be doing so, but didn't want to come off as whining. Looks like I will get what I want after all
  15. On your list of orders on the left column, you will need to add a listener which will trigger some code whenever it is clicked. This is all client side and will be implemented using JavaScript or if you prefer some JavaScript library such as jQuery. It will send some unique identifier (the order's PK if you wish) to the PHP server which will query the DB and return the results, and your javascript will then update the right column with the data received using something maybe like the following: $(".a-class-on-each-row-of-your-left-column").click( function() { $.get ( "yourServer.php", // if empty, evidently it will go to the server which rendered the page {id: $(this).data('my-id')},// data to send. Use either this or $(this) to get the ID from the row function(resp) { // process response // update your right column with code here. To see the data first, use: console.log(resp) } ) }) Maybe a little too abstract but hope you get the idea.
  16. Forgot to provide feedback on my eventual approach. Turned out I was looking for Bézier curves and splines.
  17. Thanks Barand, No answer to #1, or at least no good answer. Regarding #2, never realized such and appreciate letting me know.
  18. Why do I get the following results (specifically the second example)? I thought it would be documented under https://www.php.net/manual/en/language.types.string.php, however, the word "ampersand" doesn't appear. Also, looked at logical operators, but found nothing. Thanks function test(string $string){ printf('%s %s %s 0'.PHP_EOL, gettype($string), $string, $string==0?'==':'!='); } test('123'); test('@123'); test('1@23'); test('123@');
  19. Hello JoshEir, You will want to spend a few minutes or likely much more understanding the difference between your server code (i.e. PHP) and your client code (i.e. JavaScript or maybe just JavaScript disguised as jQuery. Assume only text can be shared between them so don't expect too much (JSON/etc allows us to push the text barrier and get more) and pay attention to where the content exists. No matter how high-tech the world seems sometimes, it really isn't.
  20. Exactly! By the way, good point that one wouldn't add temperature + humidity + pressure + power, but one might add f(temperature, humidity, pressure) + power. That being said, I've only been doing so with power and energy, and not for temperature, humidity, or pressure.
  21. I am just amazed that I can't find an existing solution. It is the stupid irregularly spaced time stamps which really limits what is available. A couple resources I found are below. https://traces.readthedocs.io/en/latest/, https://datascopeanalytics.com/blog/unevenly-spaced-time-series/, and https://github.com/datascopeanalytics/traces are right on topic. I resisted going through the code because it is written in Python and I thought I'd find something in PHP, however, this is a strong contender. https://www.php.net/manual/en/book.trader.php, and particularly the moving averages and similar functions and especially https://www.php.net/manual/en/function.trader-mavp.php are interesting. Very poorly documented, and I don't think really geared to irregular sample times, https://php-ml.readthedocs.io/en/latest/ has some good stuff, but doesn't seem to have what I am looking for. http://195.134.76.37/applets/AppletSmooth/Appl_Smooth2.html and https://en.wikipedia.org/wiki/Savitzky–Golay_filter might be relevant. It is only for evenly spaced sample points, however, maybe possible to adapt by coming up with a moving derivative and multiplying it by each group's duration and I might give it a try. https://en.wikipedia.org/wiki/Unevenly_spaced_time_series and maybe https://en.wikipedia.org/wiki/Curve_fitting and https://en.m.wikipedia.org/wiki/Smoothing are relevant.
  22. The P51, P55, etc are physical points. I also have virtual points which combine multiple physical points columns (not rows). Note that the data isn't stored in SQL and doesn't have the typical structure. There is also some use case to do math on rows such as what the difference is between two moments in time, but I don't think it is relevant to this topic. The data I just grabbed just happened to be about 3 minute increments. Values can be updated two ways. One is a poll rate where the user configures it to poll the meters ever x minutes (they just happened to be set up for 3 minutes for these four points). The other way is by change in value where the meter broadcasts (UDP) to everyone when it changes by a specified threshold. Change of value is often preferred as multiple clients can just silently listen and gain the data without creating extra network traffic. I have considered buffering the data in order to make more common writes. I have some cases where I have samples less than a second apart which I believe provides little value and is a bit of a headache. The following chart is just for a single physical point, but instead of rendering as steps, wanted to be a beautify curve like the one I tried to draw. Highcharts and others can accept just the timestamp and value for the various data points highlighted in yellow and do this, however, I don't know how to deal with virtual points which combine multiple real points with different timestamps and it also not ideal when downloading as CSV. I thought there would be some "simple" PHP approach to derive a time based formula from the real data points so I could then combine the value all the series for each sequential time interval. Sorry, always in hindsight, I realize I should have provided more detail early on. I recognize it is impossible to provide good advise without having the details, but I also don't want to others with too many details.
  23. That was data being generated randomly as I was just trying to come up with an approach to make it look "nice". Below is some raw and group by data. For this raw data subset, there aren't any rows with only a single measurement, but that is not always the case. Really, I just want the bottom chart to look prettier. What you are looking at is grouping to 400 samples, but it shows up as 20 horizontal 3 minute steps. Each of these 3 minute steps has 20 groups (20 x 20 = 400), but they are the same value because I am filling empty values with the previous value. I "could" do linear instead, but it doesn't look much better. Highcharts can deal with irregular timestamps, but I would rather output common timestamps with data for all as it would be better UX if downloaded to CSV and is more specific chart software agnostic.
  24. Nice word. Had to look it up What values? Environmental parameters such as temperature, humidity, pressure, power consumption, etc. Why are they inconsistent? Only that the actual measurements are not taken at common instance in time unless by chance. Does it make sense to group/average them like you've been doing, and if so why and how. For a query over a longer duration of time, I might have over a million samples and need to group them for obvious reasons, and for these cases I am using a GROUP BY and it works fine. My need is to come up with a strategy for short durations where I don't have multiple samples per group interval. Are you trying to interpolate data or render a chart or what? Maybe, yes, and yes. Render charts and/or provide in CSV format, and maybe interpolate data as a means to an end. I don't believe so. I can ask for the actual values with timestamps, or ask for them grouped by some time duration. When grouping, I can ask for empty groups to be filled with NULL, some given value, the previous valve, or a linier value. For short durations, I will have many occurrences of empty groups and none of these group by strategies seem to meet my needs, and since I will also not have much data to process, I believe I will be better off just requesting the actual valves and having PHP deal with making it presentable.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.